Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

interpolate-json

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interpolate-json - npm Package Compare versions

Comparing version 0.4.9 to 0.5.0

2

lib/main.js

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

"use strict";const extend=require("extend"),type=require("type-detect"),{BadRequest}=require("./exceptions"),regexEscaped=/[\\/|#<>{}()[\]^$+*?.-\:\!]/g,escapeRegex=e=>"string"===type(e)?e.replace(regexEscaped,"\\$&"):e,main=()=>{let e={debug:!1,prefix:"${",suffix:"}",subKeyPointer:"."};const t={...e},log=t=>{e.debug&&console.log(`[dotconfig][debug]: ${t}`)},trace=t=>{e.debug&&console.trace(`[dotconfig][error]: ${t}`)},getMatchSet=(e,t)=>new Set(e.reduce((e,r)=>(e.push(r.replace(t,(e,t)=>t.trim())),e),[])),getInterpolated=(e,t,r,s=!1)=>(log(`Found match: ${e.match(t)}`),e.replace(t,(e,t)=>(t=t.trim(),r.hasOwnProperty(t)?r[t].toString():s?e:""))),flattenAndResolve=(e,t,r,s)=>{let n={};return t.forEach(t=>{let i=((e,t,r)=>{let s=t.split(r).reduce((e,t)=>e[t]||{},e);return"number"===type(s)||"string"===type(s)?s:""})(e,t,s);r.test(i)&&(i=getInterpolated(i,r,n,!0)),r.test(i)?(extend(n,flattenAndResolve(e,getMatchSet(i.match(r),r),r,s)),n[t]=getInterpolated(i,r,n)):n[t]=i}),n};return{[Symbol.toStringTag]:"Interpolate-Json",do:(t,r=null,s={})=>{let n=!1,i=type(t);s.prefix&&!s.suffix&&(s.suffix=""),s=extend({},e,s);const a=(u=s,new RegExp(escapeRegex(u.prefix.trim())+"([\\s]*[\\w]+(?:"+escapeRegex(u.subKeyPointer.trim())+"[\\w]+)*[\\s]*)"+escapeRegex(u.suffix.trim()),"g"));var u;switch(i){case"Object":let e=extend({},t,r||{});if(t=JSON.stringify(t),a.test(t)){let i=t.match(a);r=flattenAndResolve(e,getMatchSet(i,a),a,s.subKeyPointer),n=!0}break;case"string":if(log(`Input: "${t}"`),!a.test(t))break;n=!0,null===r&&((e,t)=>{throw trace(e),"Exception"===type(t)?new t(e):new Error(e)})('Please provide "values"',BadRequest);break;default:return trace(`Interpolation for ${i} has not yet been implemented`),t}const c=n?getInterpolated(t,a,r):t;switch(i){case"Object":return JSON.parse(c);case"string":default:return c}},debug:()=>{e.debug=!0},reset:()=>{e={...t}}}};module.exports=main();
"use strict";const extend=require("extend"),type=require("type-detect"),{BadRequest}=require("./exceptions"),regexEscaped=/[\\/|#<>{}()[\]^$+*?.-\:\!]/g,escapeRegex=e=>"string"===type(e)?e.replace(regexEscaped,"\\$&"):e,main=()=>{let e={debug:!1,prefix:"${",suffix:"}",subKeyPointer:"."};const t={...e},log=t=>{e.debug&&console.log(`[dotconfig][debug]: ${t}`)},trace=t=>{e.debug&&console.trace(`[dotconfig][error]: ${t}`)},getMatchSet=(e,t)=>new Set(e.reduce((e,r)=>(e.push(r.replace(t,(e,t)=>t.trim())),e),[])),getInterpolated=(e,t,r,s=!1)=>(log(`Found match: ${e.match(t)}`),e.replace(t,(e,t)=>(t=t.trim(),r.hasOwnProperty(t)?r[t].toString():s?e:""))),flattenAndResolve=(e,t,r,s)=>{let n={};return t.forEach(t=>{let i=((e,t,r)=>{let s=t.split(r).reduce((e,t)=>e[t]||{},e);return"number"===type(s)||"string"===type(s)?s:""})(e,t,s);r.test(i)&&(i=getInterpolated(i,r,n,!0)),r.test(i)?(extend(n,flattenAndResolve(e,getMatchSet(i.match(r),r),r,s)),n[t]=getInterpolated(i,r,n)):n[t]=i}),n};return{[Symbol.toStringTag]:"Interpolate-Json",expand:(t,r=null,s={})=>{let n=!1,i=type(t);s.prefix&&!s.suffix&&(s.suffix=""),s=extend({},e,s);const a=(u=s,new RegExp(escapeRegex(u.prefix.trim())+"([\\s]*[\\w]+(?:"+escapeRegex(u.subKeyPointer.trim())+"[\\w]+)*[\\s]*)"+escapeRegex(u.suffix.trim()),"g"));var u;switch(i){case"Object":let e=extend({},t,r||{});if(t=JSON.stringify(t),a.test(t)){let i=t.match(a);r=flattenAndResolve(e,getMatchSet(i,a),a,s.subKeyPointer),n=!0}break;case"string":if(log(`Input: "${t}"`),!a.test(t))break;n=!0,null===r&&((e,t)=>{throw trace(e),"Exception"===type(t)?new t(e):new Error(e)})('Please provide "values"',BadRequest);break;default:return trace(`Interpolation for ${i} has not yet been implemented`),t}const c=n?getInterpolated(t,a,r):t;switch(i){case"Object":return JSON.parse(c);case"string":default:return c}},debug:()=>{e.debug=!0},reset:()=>{e={...t}}}};module.exports=main();
{
"name": "interpolate-json",
"version": "0.4.9",
"version": "0.5.0",
"description": "Interpolate a Javascript (Node.js V8) Object or string with json - Advanced",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,2 @@ # interpolate-json

status: [![Travis (.org)](https://img.shields.io/travis/Terran-Source/interpolate-json?label=Travis-build&style=plastic)](https://travis-ci.org/Terran-Source/interpolate-json) [![node](https://img.shields.io/node/v/interpolate-json)](https://www.npmjs.com/package/interpolate-json)
[![Travis (.org)](https://img.shields.io/travis/Terran-Source/interpolate-json?logo=travis&style=plastic)](https://travis-ci.org/Terran-Source/interpolate-json) [![node](https://img.shields.io/node/v/interpolate-json?logo=nodejs&style=plastic)](https://www.npmjs.com/package/interpolate-json) [![GitHub](https://img.shields.io/github/license/Terran-Source/interpolate-json?logo=github&style=plastic)](LICENSE) [![NPM version](https://img.shields.io/npm/v/interpolate-json.svg?style=plastic)](https://www.npmjs.com/package/interpolate-json)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc