Skip to content

Commit

Permalink
Merge pull request #1155 from alphagov/ldeb-replace-keypather
Browse files Browse the repository at this point in the history
Replace keypather with lodash.get
  • Loading branch information
lfdebrux authored Nov 24, 2021
2 parents 699c79a + d6d8c93 commit 266226c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 191 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Unreleased

## Fixes

[Pull request #1155: Replace lodash with keypather.get](https://github.com/alphagov/govuk-prototype-kit/pull/1155)

# 11.0.0 (Fix release)

## Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const fs = require('fs')

// NPM dependencies
const getKeypath = require('keypather/get')
const { get: getKeypath } = require('lodash')
const marked = require('marked')
const path = require('path')
const portScanner = require('portscanner')
Expand Down
48 changes: 48 additions & 0 deletions lib/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-env jest */

const nunjucks = require('nunjucks')

const utils = require('./utils.js')

describe('checked', () => {
var ctx, checked

beforeAll(() => {
var env = new nunjucks.Environment()
utils.addCheckedFunction(env)
ctx = { data: {} }
checked = env.getGlobal('checked').bind({ ctx })
})

it('can be added as global function to a nunjucks env', () => {
var env = new nunjucks.Environment()
utils.addCheckedFunction(env)
expect(env.getGlobal('checked')).toBeDefined()
})

it('returns a string', () => {
expect(checked('foo', 'bar')).toBe('')
})

it('returns checked if data has specified value', () => {
ctx.data.foo = 'bar'
expect(checked('foo', 'bar')).toBe('checked')
})

it('returns empty string if data does not has specified value', () => {
ctx.data.foo = 'baz'
expect(checked('foo', 'bar')).toBe('')
})

it('allows deep access into objects', () => {
ctx.data.foo = 'bar'
expect(checked('foo', 'bar')).toBe('checked')
ctx.data.foo = { bar: 'baz' }
expect(checked("['foo']['bar']", 'baz')).toBe('checked')
})

it('allows deep access using dot notation (undocumented)', () => {
ctx.data.foo = { bar: 'baz' }
expect(checked('foo.bar', 'baz')).toBe('checked')
})
})
190 changes: 1 addition & 189 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"gulp-sass": "^5.0.0",
"gulp-sourcemaps": "^3.0.0",
"inquirer": "^8.2.0",
"keypather": "^3.0.0",
"lodash": "^4.17.21",
"marked": "^3.0.8",
"node-sass": "^6.0.1",
"notifications-node-client": "^5.1.0",
Expand Down

0 comments on commit 266226c

Please sign in to comment.