Socket
Socket
Sign inDemoInstall

adlib

Package Overview
Dependencies
1
Maintainers
6
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.0.2

lib/cloneObject.js

9

CHANGELOG.md

@@ -5,2 +5,11 @@ # Change Log

## 3.0.2
- add release documentation
## 3.0.1
### Fixed
- perform a deep object clone of `transforms` so that the object passed in is not modified
- initial value of the transform param is `undefined` instead of `null` so that the `level` arg is properly set to 0 for `optionalTransform`
- correctly interpolate values that are empty strings
## 3.0.0

@@ -7,0 +16,0 @@ ### Breaking Changes

75

dist/adlib.js
/**
* adlib - v3.0.0 - Thu Jan 10 2019 12:46:01 GMT-0800 (Pacific Standard Time)
* adlib - v3.0.2 - Fri Aug 16 2019 11:49:44 GMT-0400 (EDT)
* Copyright (c) 2017-2019 Dave Bouwman / Esri

@@ -115,3 +115,2 @@ * Apache-2.0

function arborist (object, propertyPath) {
propertyPath = propertyPath || '';

@@ -132,8 +131,7 @@ if(Array.isArray(object)){

return getPropertyValue(object, propertyPath);
return getPropertyValue(object);
}
function iteratee(value, key){
var valuePath = propertyPath ? propertyPath + '.' + key: key;
return arborist(value, valuePath);
return arborist(value);
}

@@ -308,2 +306,46 @@ }

limitations under the License. */
/**
* ```js
* import { cloneObject } from "./cloneObject";
* const original = { foo: "bar" }
* const copy = cloneObject(original)
* copy.foo // "bar"
* copy === original // false
* ```
* Make a deep clone, including arrays. Does not handle functions!
*
* Copied from @esri/hub-common to avoid bringing along that package's
* dependencies, @esri/hub-common should be made a dependency if more
* functions are needed from it in the future
*/
var cloneObject = function (obj) {
var clone = {};
// first check array
if (Array.isArray(obj)) {
clone = obj.map(cloneObject);
} else if (typeof obj === "object") {
for (var i in obj) {
if (obj[i] != null && typeof obj[i] === "object") {
clone[i] = cloneObject(obj[i]);
} else {
clone[i] = obj[i];
}
}
} else {
clone = obj;
}
return clone;
};
/* Copyright (c) 2017-2019 Esri Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
var HANDLEBARS = /{{\s*?[\w].*?}}/g;

@@ -325,3 +367,3 @@

// we default to using the value...
var param = null;
var param;
if (transformCheck[2]){

@@ -363,3 +405,3 @@ param = transformCheck[2];

transforms = transforms || {};
transforms = cloneObject(transforms) || {};
if (transforms.optional) {

@@ -422,3 +464,8 @@ throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.');

if (!isStaticValue) {
result.value = _swap(path, settings, transforms) || entry;
var swap = _swap(path, settings, transforms);
if (swap === '') {
result.value = '';
} else {
result.value = swap || entry;
}
}

@@ -436,3 +483,3 @@ // console.info(`Value: ${JSON.stringify(result)}`);

// and it's numeric-ish
if(!isNaN(v.value)) {
if(!isNaN(v.value) && v.value !== '') {
// and has a . in it...

@@ -461,3 +508,3 @@ if (v.value.indexOf('.') > -1) {

// if we have a value, let's return that...
if (settingsValue) {
if (settingsValue || settingsValue === '') {
// console.log(`We found a value so we return it ${settingsValue}`);

@@ -503,11 +550,11 @@ return settingsValue;

exports.adlib = adlib;
exports.listDependencies = listDependencies;
exports.arborist = arborist;
exports.deepMapValues = deepMapValues;
exports.getPropertyValue = getPropertyValue;
exports.getWithDefault = getWithDefault;
exports.listDependencies = listDependencies;
exports.mapValues = mapValues;
exports.arborist = arborist;
exports.optionalTransform = optionalTransform;
exports.pruneArray = pruneArray;
exports.pruneObject = pruneObject;
exports.getPropertyValue = getPropertyValue;
exports.optionalTransform = optionalTransform;

@@ -514,0 +561,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

2

dist/adlib.min.js

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).adlib={})}(this,function(e){"use strict";var f=function(e,n,r){return void 0===r&&(r=void 0),n.split(".").reduce(function(e,n){return e?e[n]:r},e)};function u(r,t){return Object.keys(r).reduce(function(e,n){return e[n]=t(r[n],n,r),e},{})}var i=function(e){return e instanceof Date},o=function(e){return"function"==typeof e},a=function(e){return"object"==typeof e},l=function(e){return e instanceof RegExp};function c(e,r,t){return t=t||"",Array.isArray(e)?e.map(n):!e||!a(e)||i(e)||l(e)||o(e)?r(e,t):Object.assign({},e,u(e,n));function n(e,n){return c(e,r,t?t+"."+n:n)}}var t=function(e){return"object"==typeof e};function p(e,r){return r=r||"",Array.isArray(e)?s(e.map(n).filter(function(e){return null!=e})):e&&t(e)?v(u(e,n)):d(e);function n(e,n){return p(e,r?r+"."+n:n)}}function s(e){var n=e,r=e.reduce(function(e,n){if(g(n)&&m(n)){var r=y(n);e<r&&(e=r)}return e},-1);return-1<r&&(n=0===r?[]:"{{delete:"+(r-1)+"}}"),n}function v(u){var e=Object.keys(u).reduce(function(e,n){var r=u[n];if(g(r)&&m(r)){var t=y(r);t>e.maxLevel&&(e.maxLevel=t)}else e.obj[n]=r;return e},{obj:{},maxLevel:-1});return 0<e.maxLevel?1===e.maxLevel?void 0:"{{delete:"+(e.maxLevel-1)+"}}":e.obj}function d(e){var n=e;return"string"==typeof e&&m(e)&&(n=function(e){var n=e,r=y(e);n=0===r?void 0:"{{delete:"+r+"}}";return n}(e)),n}var y=function(e){return parseInt(e.replace(/{|}/g,"").split(":")[1])};function m(e){return!(!e||"string"!=typeof e)&&-1<e.indexOf("{{delete")}var g=function(e){return"string"==typeof e};function n(e,n,r,t){void 0===t&&(t=0);var u=n;return n||(u="{{delete:"+t+"}}"),u}var b=/{{\s*?[\w].*?}}/g;e.adlib=function(e,o,a){if(void 0===a&&(a=null),(a=a||{}).optional)throw new Error("Please do not pass in an `optional` transform; adlib provides that internally.");return a.optional=n,p(c(e,function(n,e){if("string"!=typeof n)return n;var r,t=n.match(b);if(t&&t.length){var i=!1;return t.map(function(e){var n=e.replace(/{|}/g,"").trim();if(-1<n.indexOf("||")){var r=n.split("||").map(function(e){return e.trim()}),u=r.length;n=r.find(function(e,n){var r,t;return r=o,t=e.split(":")[0],null!=f(r,t,null)?e:n+1===u&&(i=!0,isNaN(e)||(e=parseInt(e)),e)})}var t={key:e,value:n};return i||(t.value=function(e,n,r){var t,u=e.split(":");if(1<u.length){var i=u[0],o=u[1],a=null;if(u[2]&&(a=u[2]),!r||!r[o]||"function"!=typeof r[o])throw new Error("Attempted to apply non-existant transform "+o+" on "+i+" with params "+e);t=f(n,i),t=r[o](i,t,n,a)}else t=f(n,e);return t}(n,o,a)||e),t}).forEach(function(e){n===e.key?("string"==typeof e.value&&(isNaN(e.value)||(-1<e.value.indexOf(".")?e.value=parseFloat(e.value):e.value=parseInt(e.value))),r=e.value):n=n.replace(e.key,e.value)}),r||n}return n}))},e.listDependencies=function(e){"string"!=typeof e&&(e=JSON.stringify(e));try{return Array.from(new Set(e.match(b))).map(function(e){return e.replace(/^{{/g,"").replace(/}}$/g,"").replace(/:.+$/,"")})}catch(e){console.error(e)}},e.deepMapValues=c,e.getWithDefault=f,e.mapValues=u,e.arborist=p,e.pruneArray=s,e.pruneObject=v,e.getPropertyValue=d,e.optionalTransform=n,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).adlib={})}(this,function(e){"use strict";var l=function(e,n,r){return void 0===r&&(r=void 0),n.split(".").reduce(function(e,n){return e?e[n]:r},e)};function i(r,t){return Object.keys(r).reduce(function(e,n){return e[n]=t(r[n],n,r),e},{})}var u=function(e){return e instanceof Date},o=function(e){return"function"==typeof e},a=function(e){return"object"==typeof e},f=function(e){return e instanceof RegExp};function c(e,r,t){return t=t||"",Array.isArray(e)?e.map(n):!e||!a(e)||u(e)||f(e)||o(e)?r(e,t):Object.assign({},e,i(e,n));function n(e,n){return c(e,r,t?t+"."+n:n)}}var t=function(e){return"object"==typeof e};function p(e,n){return Array.isArray(e)?s(e.map(r).filter(function(e){return null!=e})):e&&t(e)?v(i(e,r)):d(e);function r(e,n){return p(e)}}function s(e){var n=e,r=e.reduce(function(e,n){if(g(n)&&m(n)){var r=y(n);e<r&&(e=r)}return e},-1);return-1<r&&(n=0===r?[]:"{{delete:"+(r-1)+"}}"),n}function v(i){var e=Object.keys(i).reduce(function(e,n){var r=i[n];if(g(r)&&m(r)){var t=y(r);t>e.maxLevel&&(e.maxLevel=t)}else e.obj[n]=r;return e},{obj:{},maxLevel:-1});return 0<e.maxLevel?1===e.maxLevel?void 0:"{{delete:"+(e.maxLevel-1)+"}}":e.obj}function d(e){var n=e;return"string"==typeof e&&m(e)&&(n=function(e){var n=e,r=y(e);n=0===r?void 0:"{{delete:"+r+"}}";return n}(e)),n}var y=function(e){return parseInt(e.replace(/{|}/g,"").split(":")[1])};function m(e){return!(!e||"string"!=typeof e)&&-1<e.indexOf("{{delete")}var g=function(e){return"string"==typeof e};function n(e,n,r,t){void 0===t&&(t=0);var i=n;return n||(i="{{delete:"+t+"}}"),i}var b=function(e){var n={};if(Array.isArray(e))n=e.map(b);else if("object"==typeof e)for(var r in e)null!=e[r]&&"object"==typeof e[r]?n[r]=b(e[r]):n[r]=e[r];else n=e;return n},x=/{{\s*?[\w].*?}}/g;e.adlib=function(e,a,f){if(void 0===f&&(f=null),(f=b(f)||{}).optional)throw new Error("Please do not pass in an `optional` transform; adlib provides that internally.");return f.optional=n,p(c(e,function(n,e){if(!function(e){return"string"==typeof e}(n))return n;var r,t=n.match(x);if(t&&t.length){var o=!1;return t.map(function(e){var n=e.replace(/{|}/g,"").trim();if(-1<n.indexOf("||")){var r=n.split("||").map(function(e){return e.trim()}),t=r.length;n=r.find(function(e,n){return function(e,n){var r=e.split(":")[0],t=l(n,r,null);return null!=t}(e,a)?e:n+1===t&&(o=!0,isNaN(e)||(e=parseInt(e)),e)})}var i={key:e,value:n};if(!o){var u=function(e,n,r){var t,i=e.split(":");if(1<i.length){var u,o=i[0],a=i[1];if(i[2]&&(u=i[2]),!r||!r[a]||"function"!=typeof r[a])throw new Error("Attempted to apply non-existant transform "+a+" on "+o+" with params "+e);t=l(n,o),t=r[a](o,t,n,u)}else t=l(n,e);return t}(n,a,f);i.value=""===u?"":u||e}return i}).forEach(function(e){n===e.key?("string"==typeof e.value&&(isNaN(e.value)||""===e.value||(-1<e.value.indexOf(".")?e.value=parseFloat(e.value):e.value=parseInt(e.value))),r=e.value):n=n.replace(e.key,e.value)}),r||""===r?r:n}return n}))},e.arborist=p,e.deepMapValues=c,e.getPropertyValue=d,e.getWithDefault=l,e.listDependencies=function(e){"string"!=typeof e&&(e=JSON.stringify(e));try{return Array.from(new Set(e.match(x))).map(function(e){return e.replace(/^{{/g,"").replace(/}}$/g,"").replace(/:.+$/,"")})}catch(e){console.error(e)}},e.mapValues=i,e.optionalTransform=n,e.pruneArray=s,e.pruneObject=v,Object.defineProperty(e,"__esModule",{value:!0})});
/**
* adlib - v3.0.0 - Thu Jan 10 2019 12:45:59 GMT-0800 (Pacific Standard Time)
* adlib - v3.0.2 - Fri Aug 16 2019 11:49:42 GMT-0400 (EDT)
* Copyright (c) 2017-2019 Dave Bouwman / Esri

@@ -115,3 +115,2 @@ * Apache-2.0

function arborist (object, propertyPath) {
propertyPath = propertyPath || '';

@@ -132,8 +131,7 @@ if(Array.isArray(object)){

return getPropertyValue(object, propertyPath);
return getPropertyValue(object);
}
function iteratee(value, key){
var valuePath = propertyPath ? propertyPath + '.' + key: key;
return arborist(value, valuePath);
return arborist(value);
}

@@ -308,2 +306,46 @@ }

limitations under the License. */
/**
* ```js
* import { cloneObject } from "./cloneObject";
* const original = { foo: "bar" }
* const copy = cloneObject(original)
* copy.foo // "bar"
* copy === original // false
* ```
* Make a deep clone, including arrays. Does not handle functions!
*
* Copied from @esri/hub-common to avoid bringing along that package's
* dependencies, @esri/hub-common should be made a dependency if more
* functions are needed from it in the future
*/
var cloneObject = function (obj) {
var clone = {};
// first check array
if (Array.isArray(obj)) {
clone = obj.map(cloneObject);
} else if (typeof obj === "object") {
for (var i in obj) {
if (obj[i] != null && typeof obj[i] === "object") {
clone[i] = cloneObject(obj[i]);
} else {
clone[i] = obj[i];
}
}
} else {
clone = obj;
}
return clone;
};
/* Copyright (c) 2017-2019 Esri Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
var HANDLEBARS = /{{\s*?[\w].*?}}/g;

@@ -325,3 +367,3 @@

// we default to using the value...
var param = null;
var param;
if (transformCheck[2]){

@@ -363,3 +405,3 @@ param = transformCheck[2];

transforms = transforms || {};
transforms = cloneObject(transforms) || {};
if (transforms.optional) {

@@ -422,3 +464,8 @@ throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.');

if (!isStaticValue) {
result.value = _swap(path, settings, transforms) || entry;
var swap = _swap(path, settings, transforms);
if (swap === '') {
result.value = '';
} else {
result.value = swap || entry;
}
}

@@ -436,3 +483,3 @@ // console.info(`Value: ${JSON.stringify(result)}`);

// and it's numeric-ish
if(!isNaN(v.value)) {
if(!isNaN(v.value) && v.value !== '') {
// and has a . in it...

@@ -461,3 +508,3 @@ if (v.value.indexOf('.') > -1) {

// if we have a value, let's return that...
if (settingsValue) {
if (settingsValue || settingsValue === '') {
// console.log(`We found a value so we return it ${settingsValue}`);

@@ -503,11 +550,11 @@ return settingsValue;

exports.adlib = adlib;
exports.listDependencies = listDependencies;
exports.arborist = arborist;
exports.deepMapValues = deepMapValues;
exports.getPropertyValue = getPropertyValue;
exports.getWithDefault = getWithDefault;
exports.listDependencies = listDependencies;
exports.mapValues = mapValues;
exports.arborist = arborist;
exports.optionalTransform = optionalTransform;
exports.pruneArray = pruneArray;
exports.pruneObject = pruneObject;
exports.getPropertyValue = getPropertyValue;
exports.optionalTransform = optionalTransform;

@@ -514,0 +561,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -16,2 +16,3 @@ /* Copyright (c) 2017-2019 Esri Inc.

import { optionalTransform } from './optional-transform/optional';
import { cloneObject } from './cloneObject';
const HANDLEBARS = /{{\s*?[\w].*?}}/g;

@@ -33,3 +34,3 @@

// we default to using the value...
let param = null;
let param;
if (transformCheck[2]){

@@ -69,3 +70,3 @@ param = transformCheck[2];

export function adlib (template, settings, transforms = null) {
transforms = transforms || {};
transforms = cloneObject(transforms) || {};
if (transforms.optional) {

@@ -126,6 +127,11 @@ throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.');

value: path
}
};
// if we have a valid object path, value comes from _swap
if (!isStaticValue) {
result.value = _swap(path, settings, transforms) || entry;
var swap = _swap(path, settings, transforms);
if (swap === '') {
result.value = '';
} else {
result.value = swap || entry;
}
}

@@ -143,3 +149,3 @@ // console.info(`Value: ${JSON.stringify(result)}`);

// and it's numeric-ish
if(!isNaN(v.value)) {
if(!isNaN(v.value) && v.value !== '') {
// and has a . in it...

@@ -168,3 +174,3 @@ if (v.value.indexOf('.') > -1) {

// if we have a value, let's return that...
if (settingsValue) {
if (settingsValue || settingsValue === '') {
// console.log(`We found a value so we return it ${settingsValue}`);

@@ -171,0 +177,0 @@ return settingsValue;

{
"name": "adlib",
"version": "3.0.0",
"version": "3.0.2",
"description": "Templating for deep JSON object graphs",

@@ -5,0 +5,0 @@ "main": "dist/adlib.js",

@@ -40,2 +40,7 @@ # adlib

### TypeScript
TypeScript definitions are available from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/adlib):
`npm install --save-dev @types/adlib`
# General Pattern

@@ -395,2 +400,8 @@

### Release
```
npm run build:release && npm publish
```
### License

@@ -397,0 +408,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc