Socket
Socket
Sign inDemoInstall

adlib

Package Overview
Dependencies
1
Maintainers
5
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.3.1

4

CHANGELOG.md

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

## 2.3.1
### Fixed
- changed regex pattern and added `trim` so that handlebars contents can include whitespace that will get ignored
## 2.3.0

@@ -7,0 +11,0 @@ ### Added

10

dist/adlib.js
/**
* adlib - v2.3.0 - Tue Sep 18 2018 13:23:31 GMT-0400 (EDT)
* adlib - v2.3.1 - Tue Oct 16 2018 10:35:19 GMT-0400 (EDT)
* Copyright (c) 2018 Dave Bouwman / Esri

@@ -320,3 +320,3 @@ * Apache-2.0

limitations under the License. */
var HANDLEBARS = /{{[\w].*?}}/g;
var HANDLEBARS = /{{\s*?[\w].*?}}/g;

@@ -400,7 +400,7 @@ function isString$1(v) {

// console.info(`Matched ${entry}...`);
// strip off the curlies...
var path = entry.replace(/{|}/g, '');
// strip off the curlies and trim any leading/trailing whitespace...
var path = entry.replace(/{|}/g, '').trim();
// check for || which indicate a hiearchy
if (path.indexOf('||') > -1) {
var paths = path.split('||');
var paths = path.split('||').map(function (path) { return path.trim(); });
var numberOfPaths = paths.length;

@@ -407,0 +407,0 @@ // here we check each option, in order, and return the first with a value in the hash, OR the last

@@ -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=/{{[\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,"");if(-1<n.indexOf("||")){var t=n.split("||"),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?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});
/**
* adlib - v2.3.0 - Tue Sep 18 2018 13:23:28 GMT-0400 (EDT)
* adlib - v2.3.1 - Tue Oct 16 2018 10:35:18 GMT-0400 (EDT)
* Copyright (c) 2018 Dave Bouwman / Esri

@@ -320,3 +320,3 @@ * Apache-2.0

limitations under the License. */
var HANDLEBARS = /{{[\w].*?}}/g;
var HANDLEBARS = /{{\s*?[\w].*?}}/g;

@@ -400,7 +400,7 @@ function isString$1(v) {

// console.info(`Matched ${entry}...`);
// strip off the curlies...
var path = entry.replace(/{|}/g, '');
// strip off the curlies and trim any leading/trailing whitespace...
var path = entry.replace(/{|}/g, '').trim();
// check for || which indicate a hiearchy
if (path.indexOf('||') > -1) {
var paths = path.split('||');
var paths = path.split('||').map(function (path) { return path.trim(); });
var numberOfPaths = paths.length;

@@ -407,0 +407,0 @@ // here we check each option, in order, and return the first with a value in the hash, OR the last

@@ -16,3 +16,3 @@ /* Copyright 2017 Esri

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

@@ -95,7 +95,7 @@ function isString(v) {

// console.info(`Matched ${entry}...`);
// strip off the curlies...
let path = entry.replace(/{|}/g, '');
// strip off the curlies and trim any leading/trailing whitespace...
let path = entry.replace(/{|}/g, '').trim();
// check for || which indicate a hiearchy
if (path.indexOf('||') > -1) {
var paths = path.split('||');
var paths = path.split('||').map(path => path.trim());
let numberOfPaths = paths.length;

@@ -102,0 +102,0 @@ // here we check each option, in order, and return the first with a value in the hash, OR the last

{
"name": "adlib",
"version": "2.3.0",
"version": "2.3.1",
"description": "Templating for deep JSON object graphs",

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

@@ -64,2 +64,18 @@

test('Adlib::Strings:: should replace a simple path with a string templated with whitespace', (t) => {
t.plan(1);
let template = {
value: '{{ thing.value }}'
};
let settings = {
thing: {
value: 'red'
}
};
let result = adlib(template, settings);
t.equal(result.value, 'red');
t.end();
})
test('Adlib::Strings:: allow info-window template to pass through', (t) => {

@@ -620,2 +636,30 @@

test('Adlib::Hierarchies:: templates can specify a value hierarchy that includes whitespace', (t) => {
t.plan(1);
let template = {
value: 'The value is {{ thing.value || foo }}'
};
let settings = {
thing: {
value: 'red'
}
};
let result = adlib(template, settings);
t.equal(result.value, 'The value is red');
t.end();
})
test('Adlib::Hierarchies:: templates can properly default when value includes whitespace', (t) => {
t.plan(1);
let template = {
value: 'The value is {{ thing.notExisting || foo }}'
};
let settings = {};
let result = adlib(template, settings);
t.equal(result.value, 'The value is foo');
t.end();
})
test('Adlib::Hierarchies:: templates can match on less-than-first choices', (t) => {

@@ -622,0 +666,0 @@ let template = {

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