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.2.5 to 2.3.0

4

CHANGELOG.md

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

## 2.3.0
### Added
- adlib.listDependencies function to list all variables in a template
# 2.2.5

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

/**
* adlib - v2.2.5 - Mon Jun 11 2018 09:37:18 GMT-0600 (MDT)
* adlib - v2.3.0 - Tue Sep 18 2018 13:23:31 GMT-0400 (EDT)
* Copyright (c) 2018 Dave Bouwman / Esri

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

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

@@ -391,6 +392,4 @@ function isString$1(v) {

var handlebars = /{{[\w].*?}}/g;
var hbsEntries = templateValue.match(HANDLEBARS);
var hbsEntries = templateValue.match(handlebars);
if (hbsEntries && hbsEntries.length) {

@@ -490,4 +489,27 @@ // console.log(`Got a ${hbsEntries.length} handlebar entries...`);

// read a template and spit out unique values
adlib.listDependencies = function (template) {
if (typeof template !== 'string') {
template = JSON.stringify(template);
}
try {
return Array.from(
new Set(
template.match(HANDLEBARS)
)
)
.map(function (term) {
return term.replace(/^{{/g, '').replace(/}}$/g, '').replace(/:.+$/, '')
// Node > 10 and browsers support this w/ a lookahead
// won't need to use the replace
// /(?<={{)[\w].*?(?=}})/g
})
} catch (e) {
console.error(e);
}
};
return adlib;
})));

2

dist/adlib.min.js

@@ -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 u(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,u(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=o(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=o(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}(u(e,n)):function(e){var n=e;"string"==typeof e&&a(e)&&(n=function(e){var n=e,t=o(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 o(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}return 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 interally.");return a.optional=n,r(l(e,function(n,e){if("string"!=typeof n)return n;var t,r=n.match(/{{[\w].*?}}/g);if(r&&r.length){var u=!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(o,e.split(":")[0],null)?e:n+1===r&&(u=!0,isNaN(e)||(e=parseInt(e)),e)})}var i={key:e,value:n};return u||(i.value=function(e,n,t){var r,i=e.split(":");if(1<i.length){var u=i[0],o=i[1],a=null;if(i[2]&&(a=i[2]),!t||!t[o]||"function"!=typeof t[o])throw new Error("Attempted to apply non-existant transform "+o+" on "+u+" with params "+e);r=f(n,u),r=t[o](u,r,n,a)}else r=f(n,e);return r}(n,o,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}))}});
!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});
/**
* adlib - v2.2.5 - Mon Jun 11 2018 09:37:16 GMT-0600 (MDT)
* adlib - v2.3.0 - Tue Sep 18 2018 13:23:28 GMT-0400 (EDT)
* Copyright (c) 2018 Dave Bouwman / Esri

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

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

@@ -391,6 +392,4 @@ function isString$1(v) {

var handlebars = /{{[\w].*?}}/g;
var hbsEntries = templateValue.match(HANDLEBARS);
var hbsEntries = templateValue.match(handlebars);
if (hbsEntries && hbsEntries.length) {

@@ -490,4 +489,27 @@ // console.log(`Got a ${hbsEntries.length} handlebar entries...`);

// read a template and spit out unique values
adlib.listDependencies = function (template) {
if (typeof template !== 'string') {
template = JSON.stringify(template);
}
try {
return Array.from(
new Set(
template.match(HANDLEBARS)
)
)
.map(function (term) {
return term.replace(/^{{/g, '').replace(/}}$/g, '').replace(/:.+$/, '')
// Node > 10 and browsers support this w/ a lookahead
// won't need to use the replace
// /(?<={{)[\w].*?(?=}})/g
})
} catch (e) {
console.error(e);
}
};
return adlib;
})));

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

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

@@ -86,6 +87,4 @@ function isString(v) {

var handlebars = /{{[\w].*?}}/g;
let hbsEntries = templateValue.match(HANDLEBARS);
let hbsEntries = templateValue.match(handlebars);
if (hbsEntries && hbsEntries.length) {

@@ -184,1 +183,24 @@ // console.log(`Got a ${hbsEntries.length} handlebar entries...`);

}
// read a template and spit out unique values
adlib.listDependencies = function (template) {
if (typeof template !== 'string') {
template = JSON.stringify(template)
}
try {
return Array.from(
new Set(
template.match(HANDLEBARS)
)
)
.map(term => {
return term.replace(/^{{/g, '').replace(/}}$/g, '').replace(/:.+$/, '')
// Node > 10 and browsers support this w/ a lookahead
// won't need to use the replace
// /(?<={{)[\w].*?(?=}})/g
})
} catch (e) {
console.error(e)
}
}
{
"name": "adlib",
"version": "2.2.5",
"version": "2.3.0",
"description": "Templating for deep JSON object graphs",
"main": "dist/adlib.umd.js",
"main": "dist/adlib.js",
"browser": "dist/adlib.min.js",

@@ -7,0 +7,0 @@ "scripts": {

@@ -18,2 +18,10 @@ # adlib

## API
```js
import adlib from 'adlib'
adlib(template, settings) // renders an adlib template
adlib.listDependencies(template) // list all dependecies of an adlib template
```
# General Pattern

@@ -38,2 +46,9 @@

# List dependencies
Gets a list of all variables your template depends upon
```js
const template = 'Injuries: {{CRASHID}}<br />On Scene: {{ISREPORTONSCENE}}'
const deps = listDependencies(template); // CRASHID, ISREPORTONSCNE
```
# Supported Interpolations

@@ -40,0 +55,0 @@

@@ -82,2 +82,23 @@

test('Adlib::listDependencies:: parse dependecies from a string', (t) => {
const template = 'Injuries: {{CRASHID}}<br />Fatalities: {{ISREPORTONSCENE}} Foo: {{CRASHID}}'
const deps = new Set(adlib.listDependencies(template));
t.deepEqual(deps, new Set('CRASHID', 'ISREPORTONSCENE'));
t.end();
})
test('Adlib::listDependencies:: parse dependecies from a string with transforms', (t) => {
const template = 'Injuries: {{CRASHID:toIso}} <br />Fatalities: {{ISREPORTONSCENE}} Foo: {{CRASHID}} Bar: {{bar.baz.bing}}'
const deps = new Set(adlib.listDependencies(template));
t.deepEqual(deps, new Set('CRASHID', 'ISREPORTONSCENE', 'bar.baz.bing'));
t.end();
})
test('Adlib::listDependencies:: parse dependecies from an object', (t) => {
const template = {key: 'Injuries: {{CRASHID}}<br />Fatalities: {{ISREPORTONSCENE}} Foo: {{CRASHID}}'}
const deps = new Set(adlib.listDependencies(template));
t.deepEqual(deps, new Set('CRASHID', 'ISREPORTONSCENE'));
t.end();
})
test('Adlib::Strings:: should replace a path within a larger string', (t) => {

@@ -84,0 +105,0 @@ t.plan(1);

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