@untool/core
Advanced tools
Comparing version 2.0.1 to 2.1.0
const { join } = require('path'); | ||
const test = require('ava'); | ||
const sinon = require('sinon'); | ||
const { initialize } = require('..'); | ||
@@ -110,2 +111,25 @@ | ||
test('Should ignore non-string values when checking for placeholders', (t) => { | ||
const spy = sinon.spy(RegExp.prototype, 'test'); | ||
const preset = { | ||
result1: () => '[SOME_ENV_VAR]', | ||
result2: () => '<result1>', | ||
result3: 'foobar', | ||
result4: '<result3>', | ||
result5: '[UNTOOL_TEST_KEY]', | ||
mixins: [join(__dirname, 'fixtures', 'config-mixin')], | ||
}; | ||
const instance = initialize(preset); | ||
const config = instance.getConfig(); | ||
t.is(preset.result1, config.result1); | ||
t.is(preset.result2, config.result2); | ||
t.false(spy.calledWith(preset.result1)); | ||
t.false(spy.calledWith(preset.result2)); | ||
t.true(spy.calledWith('<result3>')); | ||
t.true(spy.calledWith('[UNTOOL_TEST_KEY]')); | ||
spy.restore(); | ||
}); | ||
test('Should support validate stategie decorator', (t) => { | ||
@@ -112,0 +136,0 @@ const instance = initialize({ |
@@ -6,2 +6,18 @@ # Change Log | ||
# [2.1.0](https://github.com/untool/untool/compare/v2.0.1...v2.1.0) (2020-02-07) | ||
### Bug Fixes | ||
* **core:** handle functions as config values appropriately ([4bcc49f](https://github.com/untool/untool/commit/4bcc49f85cc7851c55ca0c6496464f6507310ee8)) | ||
### Features | ||
* support latest Node.js (v13) ([dbc3d1e](https://github.com/untool/untool/commit/dbc3d1e7e9c80a6b1ea736824252fafc03e7e754)) | ||
## [2.0.1](https://github.com/untool/untool/compare/v2.0.0...v2.0.1) (2020-01-20) | ||
@@ -8,0 +24,0 @@ |
@@ -83,3 +83,3 @@ 'use strict'; | ||
} | ||
if (regExp.test(item)) { | ||
if (typeof item === 'string' && regExp.test(item)) { | ||
return item.replace(regExp, (_, key) => | ||
@@ -111,3 +111,3 @@ replaceRecursive(flatConfig[key] || '') | ||
} | ||
if (regExp.test(item)) { | ||
if (typeof item === 'string' && regExp.test(item)) { | ||
return item.replace(regExp, (_, key, fallback) => { | ||
@@ -114,0 +114,0 @@ const replaced = env[key] || fallback || ''; |
@@ -0,1 +1,3 @@ | ||
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_" }] */ | ||
'use strict'; | ||
@@ -6,4 +8,5 @@ | ||
const Ajv = require('ajv'); | ||
const isPlainObject = require('is-plain-obj'); | ||
const configureAjv = (ajv) => | ||
const configureAjv = (ajv) => { | ||
ajv.addKeyword('absolutePath', { | ||
@@ -33,7 +36,43 @@ errors: true, | ||
}); | ||
ajv.addKeyword('isFunction', { | ||
compile(expected, schema) { | ||
const callback = (data) => { | ||
if (isPlainObject(data)) { | ||
const values = Object.values(data); | ||
return values.length === 0 || values.every((data) => callback(data)); | ||
} | ||
if ((typeof data === 'function') !== expected) { | ||
callback.errors = [ | ||
{ | ||
keyword: 'isFunction', | ||
params: { isFunction: data }, | ||
message: `${expected ? 'should' : 'should not'} be a function`, | ||
parentSchema: schema, | ||
}, | ||
]; | ||
return false; | ||
} | ||
return true; | ||
}; | ||
callback.errors = []; | ||
return callback; | ||
}, | ||
}); | ||
}; | ||
exports.validate = (config, properties) => { | ||
const ajv = new Ajv({ allErrors: true }); | ||
const additional = { | ||
patternProperties: { | ||
'^.*$': { | ||
isFunction: false, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}; | ||
const { _config, _env, ...baseConfig } = config; | ||
configureAjv(ajv); | ||
if (ajv.validate({ properties }, config)) { | ||
if (ajv.validate({ properties, ...additional }, baseConfig)) { | ||
return []; | ||
@@ -40,0 +79,0 @@ } else { |
{ | ||
"name": "@untool/core", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "untool core", | ||
@@ -34,5 +34,5 @@ "repository": { | ||
"engines": { | ||
"node": "^10.13 || ^12.13" | ||
"node": "^10.13 || ^12.13 || ^13.0" | ||
}, | ||
"gitHead": "1ed715ff3e102e39dd6869502389d4d0f48b0a1e" | ||
"gitHead": "ab47517ea56a629a19cd9fe580cf35981395dfd9" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
51330
671
0