adlib
Advanced tools
Comparing version 2.3.1 to 3.0.0
@@ -5,2 +5,17 @@ # Change Log | ||
## 3.0.0 | ||
### Breaking Changes | ||
- this library no longer mixes default and named [exports](https://rollupjs.org/guide/en#exporting). | ||
```js | ||
import { adlib } from "adlib"; | ||
import { mapValues } from "adlib"; | ||
// NOT | ||
// import adlib from "adlib"; | ||
// import mapValues from "adlib"; | ||
``` | ||
Since `adlib` is the namespace for _all_ the functions we export, this means that UMD consumers will now call `adlib.adlib()`. | ||
## 2.3.1 | ||
@@ -7,0 +22,0 @@ ### Fixed |
/** | ||
* adlib - v2.3.1 - Tue Oct 16 2018 10:35:19 GMT-0400 (EDT) | ||
* Copyright (c) 2018 Dave Bouwman / Esri | ||
* adlib - v3.0.0 - Thu Jan 10 2019 12:46:01 GMT-0800 (Pacific Standard Time) | ||
* Copyright (c) 2017-2019 Dave Bouwman / Esri | ||
* Apache-2.0 | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.adlib = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.adlib = {})); | ||
}(this, function (exports) { 'use strict'; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -26,11 +26,11 @@ you may not use this file except in compliance with the License. | ||
*/ | ||
function getWithDefault (obj, path, defaultValue) { | ||
var getWithDefault = function (obj, path, defaultValue) { | ||
if ( defaultValue === void 0 ) defaultValue = undefined; | ||
return path | ||
.split('.') | ||
.reduce(function (o, p) { return o ? o[p] : defaultValue; }, obj) | ||
} | ||
.split('.') | ||
.reduce(function (o, p) { return o ? o[p] : defaultValue; }, obj); | ||
}; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -61,3 +61,3 @@ you may not use this file except in compliance with the License. | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -73,19 +73,11 @@ you may not use this file except in compliance with the License. | ||
function isDate (v) { | ||
return v instanceof Date | ||
} | ||
var isDate = function (v) { return v instanceof Date; }; | ||
function isFunction (v) { | ||
return typeof v === 'function' | ||
} | ||
var isFunction = function (v) { return typeof v === 'function'; }; | ||
function isObject (v) { | ||
return typeof v === 'object' | ||
} | ||
var isObject = function (v) { return typeof v === 'object'; }; | ||
function isRegExp (v) { | ||
return v instanceof RegExp | ||
} | ||
var isRegExp = function (v) { return v instanceof RegExp; }; | ||
function deepMapValues(object, callback, propertyPath, that) { | ||
function deepMapValues(object, callback, propertyPath) { | ||
propertyPath = propertyPath || ''; | ||
@@ -109,3 +101,3 @@ if(Array.isArray(object)){ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -121,5 +113,3 @@ you may not use this file except in compliance with the License. | ||
function isObject$1 (v) { | ||
return typeof v === 'object' | ||
} | ||
var isObject$1 = function (v) { return typeof v === 'object'; }; | ||
@@ -262,5 +252,3 @@ /** | ||
*/ | ||
function getLevel (value) { | ||
return parseInt(value.replace(/{|}/g, '').split(':')[1]); | ||
} | ||
var getLevel = function (value) { return parseInt(value.replace(/{|}/g, '').split(':')[1]); }; | ||
@@ -278,7 +266,5 @@ /** | ||
function isString (v) { | ||
return typeof v === 'string'; | ||
} | ||
var isString = function (v) { return typeof v === 'string'; }; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -306,3 +292,3 @@ you may not use this file except in compliance with the License. | ||
function optional(key, value, settings, level) { | ||
function optionalTransform(key, value, settings, level) { | ||
if ( level === void 0 ) level = 0; | ||
@@ -318,3 +304,3 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -331,5 +317,3 @@ you may not use this file except in compliance with the License. | ||
function isString$1(v) { | ||
return typeof v === 'string'; | ||
} | ||
var isString$1 = function (v) { return typeof v === 'string'; }; | ||
@@ -382,3 +366,3 @@ function _swap(parameter, settings, transforms) { | ||
// Combine a Template with Settings | ||
function adlib(template, settings, transforms) { | ||
function adlib (template, settings, transforms) { | ||
if ( transforms === void 0 ) transforms = null; | ||
@@ -388,5 +372,5 @@ | ||
if (transforms.optional) { | ||
throw new Error('Please do not pass in an `optional` transform, adlib provides that interally.'); | ||
throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.'); | ||
} else { | ||
transforms.optional = optional; | ||
transforms.optional = optionalTransform; | ||
} | ||
@@ -500,3 +484,3 @@ | ||
// read a template and spit out unique values | ||
adlib.listDependencies = function (template) { | ||
function listDependencies (template) { | ||
if (typeof template !== 'string') { | ||
@@ -521,6 +505,17 @@ template = JSON.stringify(template); | ||
} | ||
}; | ||
} | ||
return adlib; | ||
exports.adlib = adlib; | ||
exports.listDependencies = listDependencies; | ||
exports.deepMapValues = deepMapValues; | ||
exports.getWithDefault = getWithDefault; | ||
exports.mapValues = mapValues; | ||
exports.arborist = arborist; | ||
exports.pruneArray = pruneArray; | ||
exports.pruneObject = pruneObject; | ||
exports.getPropertyValue = getPropertyValue; | ||
exports.optionalTransform = optionalTransform; | ||
}))); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.adlib=n()}(this,function(){"use strict";function f(e,n,t){return void 0===t&&(t=void 0),n.split(".").reduce(function(e,n){return e?e[n]:t},e)}function o(t,r){return Object.keys(t).reduce(function(e,n){return e[n]=r(t[n],n,t),e},{})}function l(e,t,r,n){return r=r||"",Array.isArray(e)?e.map(i):!e||"object"!=typeof e||e instanceof Date||e instanceof RegExp||"function"==typeof e?t(e,r):Object.assign({},e,o(e,i));function i(e,n){return l(e,t,r?r+"."+n:n)}}function r(e,t){return t=t||"",Array.isArray(e)?function(e){var n=e,t=e.reduce(function(e,n){if(c(n)&&a(n)){var t=u(n);e<t&&(e=t)}return e},-1);-1<t&&(n=0===t?[]:"{{delete:"+(t-1)+"}}");return n}(e.map(n).filter(function(e){return null!=e})):e&&"object"==typeof e?function(i){var e,n=Object.keys(i).reduce(function(e,n){var t=i[n];if(c(t)&&a(t)){var r=u(t);r>e.maxLevel&&(e.maxLevel=r)}else e.obj[n]=t;return e},{obj:{},maxLevel:-1});e=0<n.maxLevel?1===n.maxLevel?void 0:"{{delete:"+(n.maxLevel-1)+"}}":n.obj;return e}(o(e,n)):function(e){var n=e;"string"==typeof e&&a(e)&&(n=function(e){var n=e,t=u(e);n=0===t?void 0:"{{delete:"+t+"}}";return n}(e));return n}(e);function n(e,n){return r(e,t?t+"."+n:n)}}function u(e){return parseInt(e.replace(/{|}/g,"").split(":")[1])}function a(e){return!(!e||"string"!=typeof e)&&-1<e.indexOf("{{delete")}function c(e){return"string"==typeof e}function n(e,n,t,r){void 0===r&&(r=0);var i=n;return n||(i="{{delete:"+r+"}}"),i}var i=/{{\s*?[\w].*?}}/g;function e(e,u,a){if(void 0===a&&(a=null),(a=a||{}).optional)throw new Error("Please do not pass in an `optional` transform, adlib provides that interally.");return a.optional=n,r(l(e,function(n,e){if("string"!=typeof n)return n;var t,r=n.match(i);if(r&&r.length){var o=!1;return r.map(function(e){var n=e.replace(/{|}/g,"").trim();if(-1<n.indexOf("||")){var t=n.split("||").map(function(e){return e.trim()}),r=t.length;n=t.find(function(e,n){return null!=f(u,e.split(":")[0],null)?e:n+1===r&&(o=!0,isNaN(e)||(e=parseInt(e)),e)})}var i={key:e,value:n};return o||(i.value=function(e,n,t){var r,i=e.split(":");if(1<i.length){var o=i[0],u=i[1],a=null;if(i[2]&&(a=i[2]),!t||!t[u]||"function"!=typeof t[u])throw new Error("Attempted to apply non-existant transform "+u+" on "+o+" with params "+e);r=f(n,o),r=t[u](o,r,n,a)}else r=f(n,e);return r}(n,u,a)||e),i}).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))),t=e.value):n=n.replace(e.key,e.value)}),t||n}return n}))}return e.listDependencies=function(e){"string"!=typeof e&&(e=JSON.stringify(e));try{return Array.from(new Set(e.match(i))).map(function(e){return e.replace(/^{{/g,"").replace(/}}$/g,"").replace(/:.+$/,"")})}catch(e){console.error(e)}},e}); | ||
!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})}); |
/** | ||
* adlib - v2.3.1 - Tue Oct 16 2018 10:35:18 GMT-0400 (EDT) | ||
* Copyright (c) 2018 Dave Bouwman / Esri | ||
* adlib - v3.0.0 - Thu Jan 10 2019 12:45:59 GMT-0800 (Pacific Standard Time) | ||
* Copyright (c) 2017-2019 Dave Bouwman / Esri | ||
* Apache-2.0 | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.adlib = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.adlib = {})); | ||
}(this, function (exports) { 'use strict'; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -26,11 +26,11 @@ you may not use this file except in compliance with the License. | ||
*/ | ||
function getWithDefault (obj, path, defaultValue) { | ||
var getWithDefault = function (obj, path, defaultValue) { | ||
if ( defaultValue === void 0 ) defaultValue = undefined; | ||
return path | ||
.split('.') | ||
.reduce(function (o, p) { return o ? o[p] : defaultValue; }, obj) | ||
} | ||
.split('.') | ||
.reduce(function (o, p) { return o ? o[p] : defaultValue; }, obj); | ||
}; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -61,3 +61,3 @@ you may not use this file except in compliance with the License. | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -73,19 +73,11 @@ you may not use this file except in compliance with the License. | ||
function isDate (v) { | ||
return v instanceof Date | ||
} | ||
var isDate = function (v) { return v instanceof Date; }; | ||
function isFunction (v) { | ||
return typeof v === 'function' | ||
} | ||
var isFunction = function (v) { return typeof v === 'function'; }; | ||
function isObject (v) { | ||
return typeof v === 'object' | ||
} | ||
var isObject = function (v) { return typeof v === 'object'; }; | ||
function isRegExp (v) { | ||
return v instanceof RegExp | ||
} | ||
var isRegExp = function (v) { return v instanceof RegExp; }; | ||
function deepMapValues(object, callback, propertyPath, that) { | ||
function deepMapValues(object, callback, propertyPath) { | ||
propertyPath = propertyPath || ''; | ||
@@ -109,3 +101,3 @@ if(Array.isArray(object)){ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -121,5 +113,3 @@ you may not use this file except in compliance with the License. | ||
function isObject$1 (v) { | ||
return typeof v === 'object' | ||
} | ||
var isObject$1 = function (v) { return typeof v === 'object'; }; | ||
@@ -262,5 +252,3 @@ /** | ||
*/ | ||
function getLevel (value) { | ||
return parseInt(value.replace(/{|}/g, '').split(':')[1]); | ||
} | ||
var getLevel = function (value) { return parseInt(value.replace(/{|}/g, '').split(':')[1]); }; | ||
@@ -278,7 +266,5 @@ /** | ||
function isString (v) { | ||
return typeof v === 'string'; | ||
} | ||
var isString = function (v) { return typeof v === 'string'; }; | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -306,3 +292,3 @@ you may not use this file except in compliance with the License. | ||
function optional(key, value, settings, level) { | ||
function optionalTransform(key, value, settings, level) { | ||
if ( level === void 0 ) level = 0; | ||
@@ -318,3 +304,3 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -331,5 +317,3 @@ you may not use this file except in compliance with the License. | ||
function isString$1(v) { | ||
return typeof v === 'string'; | ||
} | ||
var isString$1 = function (v) { return typeof v === 'string'; }; | ||
@@ -382,3 +366,3 @@ function _swap(parameter, settings, transforms) { | ||
// Combine a Template with Settings | ||
function adlib(template, settings, transforms) { | ||
function adlib (template, settings, transforms) { | ||
if ( transforms === void 0 ) transforms = null; | ||
@@ -388,5 +372,5 @@ | ||
if (transforms.optional) { | ||
throw new Error('Please do not pass in an `optional` transform, adlib provides that interally.'); | ||
throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.'); | ||
} else { | ||
transforms.optional = optional; | ||
transforms.optional = optionalTransform; | ||
} | ||
@@ -500,3 +484,3 @@ | ||
// read a template and spit out unique values | ||
adlib.listDependencies = function (template) { | ||
function listDependencies (template) { | ||
if (typeof template !== 'string') { | ||
@@ -521,6 +505,17 @@ template = JSON.stringify(template); | ||
} | ||
}; | ||
} | ||
return adlib; | ||
exports.adlib = adlib; | ||
exports.listDependencies = listDependencies; | ||
exports.deepMapValues = deepMapValues; | ||
exports.getWithDefault = getWithDefault; | ||
exports.mapValues = mapValues; | ||
exports.arborist = arborist; | ||
exports.pruneArray = pruneArray; | ||
exports.pruneObject = pruneObject; | ||
exports.getPropertyValue = getPropertyValue; | ||
exports.optionalTransform = optionalTransform; | ||
}))); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); |
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -12,11 +12,9 @@ you may not use this file except in compliance with the License. | ||
import getWithDefault from './getWithDefault'; | ||
import deepMapValues from './deepMap'; | ||
import {arborist} from './optional-transform/arborist'; | ||
import optionalTransform from './optional-transform/optional'; | ||
import { getWithDefault } from './getWithDefault'; | ||
import { deepMapValues } from './deepMap'; | ||
import { arborist } from './optional-transform/arborist'; | ||
import { optionalTransform } from './optional-transform/optional'; | ||
const HANDLEBARS = /{{\s*?[\w].*?}}/g; | ||
function isString(v) { | ||
return typeof v === 'string'; | ||
} | ||
const isString = (v) => typeof v === 'string'; | ||
@@ -69,6 +67,6 @@ function _swap(parameter, settings, transforms) { | ||
// Combine a Template with Settings | ||
export default function adlib(template, settings, transforms = null) { | ||
export function adlib (template, settings, transforms = null) { | ||
transforms = transforms || {}; | ||
if (transforms.optional) { | ||
throw new Error('Please do not pass in an `optional` transform, adlib provides that interally.'); | ||
throw new Error('Please do not pass in an `optional` transform; adlib provides that internally.'); | ||
} else { | ||
@@ -185,3 +183,3 @@ transforms.optional = optionalTransform; | ||
// read a template and spit out unique values | ||
adlib.listDependencies = function (template) { | ||
export function listDependencies (template) { | ||
if (typeof template !== 'string') { | ||
@@ -207,1 +205,2 @@ template = JSON.stringify(template) | ||
} | ||
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -15,21 +15,13 @@ you may not use this file except in compliance with the License. | ||
*/ | ||
import mapValues from './mapValues'; | ||
import { mapValues } from './mapValues'; | ||
function isDate (v) { | ||
return v instanceof Date | ||
} | ||
const isDate = (v) => v instanceof Date; | ||
function isFunction (v) { | ||
return typeof v === 'function' | ||
} | ||
const isFunction = (v) => typeof v === 'function'; | ||
function isObject (v) { | ||
return typeof v === 'object' | ||
} | ||
const isObject = (v) => typeof v === 'object'; | ||
function isRegExp (v) { | ||
return v instanceof RegExp | ||
} | ||
const isRegExp = (v) => v instanceof RegExp; | ||
export default function deepMapValues(object, callback, propertyPath, that) { | ||
export function deepMapValues(object, callback, propertyPath) { | ||
propertyPath = propertyPath || ''; | ||
@@ -36,0 +28,0 @@ if(Array.isArray(object)){ |
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -15,6 +15,4 @@ you may not use this file except in compliance with the License. | ||
*/ | ||
export default function getWithDefault (obj, path, defaultValue = undefined) { | ||
return path | ||
.split('.') | ||
.reduce((o, p) => o ? o[p] : defaultValue, obj) | ||
} | ||
export const getWithDefault = (obj, path, defaultValue = undefined) => path | ||
.split('.') | ||
.reduce((o, p) => o ? o[p] : defaultValue, obj); |
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -15,3 +15,3 @@ you may not use this file except in compliance with the License. | ||
*/ | ||
export default function mapValues (obj, fn) { | ||
export function mapValues (obj, fn) { | ||
let keys = Object.keys(obj); | ||
@@ -18,0 +18,0 @@ // console.info(`keys: ${keys}`); |
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -20,7 +20,5 @@ you may not use this file except in compliance with the License. | ||
// import mapValues from 'lodash.mapvalues'; | ||
import mapValues from '../mapValues'; | ||
import { mapValues } from '../mapValues'; | ||
function isObject (v) { | ||
return typeof v === 'object' | ||
} | ||
const isObject = (v) => typeof v === 'object'; | ||
@@ -163,5 +161,3 @@ /** | ||
*/ | ||
function getLevel (value) { | ||
return parseInt(value.replace(/{|}/g, '').split(':')[1]); | ||
} | ||
const getLevel = (value) => parseInt(value.replace(/{|}/g, '').split(':')[1]); | ||
@@ -179,4 +175,2 @@ /** | ||
function isString (v) { | ||
return typeof v === 'string'; | ||
} | ||
const isString = (v) => typeof v === 'string'; |
@@ -1,2 +0,2 @@ | ||
/* Copyright 2017 Esri | ||
/* Copyright (c) 2017-2019 Esri Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -24,3 +24,3 @@ you may not use this file except in compliance with the License. | ||
export default function optional(key, value, settings, level = 0) { | ||
export function optionalTransform(key, value, settings, level = 0) { | ||
// console.log(`optional: ${key}, ${value}, ${level}`); | ||
@@ -27,0 +27,0 @@ let val = value; |
{ | ||
"name": "adlib", | ||
"version": "2.3.1", | ||
"version": "3.0.0", | ||
"description": "Templating for deep JSON object graphs", | ||
"main": "dist/adlib.js", | ||
"browser": "dist/adlib.min.js", | ||
"module": "lib/index.js", | ||
"unpkg": "dist/adlib.umd.js", | ||
"files": [ | ||
"dist/**", | ||
"lib/**" | ||
], | ||
"scripts": { | ||
@@ -70,9 +75,9 @@ "start": "npm run build && concurrently \"watch 'npm run build' lib\" \"mocha -w\"", | ||
"mocha": "^5.2.0", | ||
"rollup": "^0.60.2", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-filesize": "^2.0.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"rollup": "^1.0.1", | ||
"rollup-plugin-babel": "^4.2.0", | ||
"rollup-plugin-buble": "^0.19.6", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-filesize": "^6.0.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"tape": "^4.8.0", | ||
@@ -79,0 +84,0 @@ "watch": "^1.0.2" |
@@ -18,9 +18,23 @@ # adlib | ||
## API | ||
## Usage | ||
### ES Module | ||
```js | ||
import adlib from 'adlib' | ||
import { adlib, listDependencies } from 'adlib' | ||
adlib(template, settings) // renders an adlib template | ||
adlib.listDependencies(template) // list all dependecies of an adlib template | ||
listDependencies(template) // list all dependecies of an adlib template | ||
``` | ||
### Browser (from CDN) | ||
This package is distributed as a [UMD](https://github.com/umdjs/umd) module and can also be used in AMD based systems or as a global under the `adlib` namespace. | ||
```html | ||
<script src="https://unpkg.com/adlib"></script> | ||
``` | ||
```js | ||
adlib.adlib(template, settings) | ||
adlib.listDependencies(template) | ||
``` | ||
@@ -50,3 +64,3 @@ # General Pattern | ||
const template = 'Injuries: {{CRASHID}}<br />On Scene: {{ISREPORTONSCENE}}' | ||
const deps = listDependencies(template); // CRASHID, ISREPORTONSCNE | ||
const deps = adlib.listDependencies(template); // CRASHID, ISREPORTONSCENE | ||
``` | ||
@@ -272,3 +286,3 @@ | ||
| 2 | the grand-parent object/array | | ||
| ... | ... up the hiearchy | | ||
| ... | ... up the hierarchy | | ||
@@ -385,3 +399,3 @@ ### Path Hierarchies | ||
Copyright 2017 Esri | ||
Copyright © 2017-2019 Esri | ||
@@ -388,0 +402,0 @@ Licensed under the Apache License, Version 2.0 (the "License"); |
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
411
140453
17
1368
1