flatulence
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -1,3 +0,3 @@ | ||
const inflate = require('./inflate') | ||
const deflate = require('./deflate') | ||
const unflatten = require('./unflatten') | ||
const flatten = require('./flatten') | ||
@@ -8,8 +8,8 @@ const flatulence = { | ||
deflate, | ||
flatten: deflate, | ||
deflate: flatten, | ||
flatten, | ||
inflate, | ||
unflatten: inflate, | ||
inflate: unflatten, | ||
unflatten, | ||
} | ||
@@ -16,0 +16,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.flatulence=n():t.flatulence=n()}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){"use strict";t.exports=e(2)},function(t,n){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r={flatten:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},f=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(null!==t&&"object"===("undefined"==typeof t?"undefined":e(t))){var c=Object.keys(t);return!c.length&&f?(o[n]=t,o):(c.forEach(function(e){return r.flatten(t[e],i(n,e,Array.isArray(t)),o,f)}),o)}return o[u(n)]=t,o}};r.flatten.keepEmpty=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=!0;return r.flatten(t,n,e,o)};var o=function(t){return t.charAt(t.length-1)},u=function(t){var n=t.length-1;return"."===o(t)?t.substring(0,n):t},i=function(t,n){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return e?u(t)+"["+n+"]":t?t+"."+n:n};t.exports=r.flatten},function(t,n,e){"use strict";var r=e(3),o=e(1),u={toFlatArray:function(){throw new Error("not implemented yet")},deflate:o,flatten:o,inflate:r,unflatten:r};t.exports=u},function(t,n){"use strict";var e=!1,r={inflate:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments[2];r||(r=o(t,n)?[]:{});var f=u(t,n);return e&&console.log("subMap",n,f),Object.keys(f).forEach(function(t){return i(t,f[t],r)}),r}},o=function(t,n){var e=Object.keys(t).find(function(t){return t.startsWith(n)});return e&&"["===e.charAt(n.length)},u=function(t,n){return Object.keys(t).reduce(function(e,r){return r.startsWith(n)&&(e[r.substring(n.length)]=t[r]),e},{})},i=function t(n,e,r){var o=n.split(t.regex).filter(function(t){return!!t});return f(o,e,r)};i.regex=/\.|(\[\d\])/;var f=function t(n,r,o){if(e&&console.log("setRec",n,r),n.length){var u=n.shift(),i=c(u),f=o[i];if(!f){var s=n[0];o[i]=l(i,s,r)}return t(n,r,o[i])}return o},c=function(t){return t.startsWith("[")?t.substring(1,t.length-1):t},l=function(t,n,e){return n?n.startsWith("[")?[]:{}:e};t.exports=r.inflate}])}); | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.flatulence=n():t.flatulence=n()}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){"use strict";t.exports=e(2)},function(t,n){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r={flatten:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},f=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(null!==t&&"object"===("undefined"==typeof t?"undefined":e(t))){var a=Object.keys(t);return!a.length&&f?(o[n]=t,o):(a.forEach(function(e){return r.flatten(t[e],i(n,e,Array.isArray(t)),o,f)}),o)}return o[u(n)]=t,o}};r.flatten.keepEmpty=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=!0;return r.flatten(t,n,e,o)};var o=function(t){return t.charAt(t.length-1)},u=function(t){var n=t.length-1;return"."===o(t)?t.substring(0,n):t},i=function(t,n){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return e?u(t)+"["+n+"]":t?t+"."+n:n};t.exports=r.flatten},function(t,n,e){"use strict";var r=e(3),o=e(1),u={toFlatArray:function(){throw new Error("not implemented yet")},deflate:o,flatten:o,inflate:r,unflatten:r};t.exports=u},function(t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var e=function(){function t(t,n){var e=[],r=!0,o=!1,u=void 0;try{for(var i,f=t[Symbol.iterator]();!(r=(i=f.next()).done)&&(e.push(i.value),!n||e.length!==n);r=!0);}catch(t){o=!0,u=t}finally{try{!r&&f.return&&f.return()}finally{if(o)throw u}}return e}return function(n,e){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return t(n,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.exports=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments[2],u=Object.entries(t).filter(function(t){var r=e(t,1),o=r[0];return o.startsWith(n)});return r||(r=i(u[0],n)),u.map(function(t){var r=e(t,2),o=r[0],u=r[1];return[f(o,n),u]}).reduce(o,r)};var r=n.isArray=function(t,n){return t&&t[0]&&"["===t[0].charAt(n.length)},o=n.setAtPath=function(t,n){var r=e(n,2),o=r[0],i=r[1],f=o.split(/\.|(\[\d\])/).filter(function(t){return!!t});return u(f,i,t),t},u=n.resolvePath=function t(n,e,r){if(n.length){var o=a(n.shift());if(!r[o]){var u=n[0];r[o]=s(u,e)}return t(n,e,r[o])}},i=n.prepareResult=function(t,n){return r(t,n)?[]:{}},f=n.cutPrefix=function(t,n){return n?t.substring(n.length):t},a=n.cleanKey=function(t){return c(t)?l(t):t},c=n.isArrayIndex=function(t){return t.startsWith("[")},l=n.extractIndex=function(t){return t.substring(1,t.length-1)},s=n.getNextValue=function(t,n){return t?c(t)?[]:{}:n}}])}); |
{ | ||
"name": "flatulence", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"description": "Flatten objects and arrays so that each key is the full path to a primitive value. Paths are lodash-compatible. Inflate flattened objects and make them regular JS objects again.", | ||
@@ -8,2 +8,3 @@ "main": "lib/main.js", | ||
"build": "webpack -p --out-dir lib", | ||
"watch": "webpack -p --watch --out-dir lib", | ||
"test": "mocha test", | ||
@@ -32,2 +33,3 @@ "test:build": "npm run build && npm run test" | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-stage-0": "^6.22.0", | ||
"lodash": "^4.16.6", | ||
@@ -34,0 +36,0 @@ "mocha": "^3.1.2", |
@@ -13,2 +13,3 @@ # flatulence | ||
// Create a flat object | ||
@@ -30,2 +31,3 @@ const flattened = flatulence.flatten({ | ||
// Optionally you can decide to keep empty arrays and objects | ||
@@ -48,2 +50,3 @@ const flattened = fl.flatten.keepEmpty({ | ||
// Create a flat object and provide a prefix to each key | ||
@@ -54,3 +57,2 @@ var flattened2 = flatulence.flatten( | ||
) | ||
//{ | ||
@@ -65,8 +67,5 @@ // 'my.prefix.key.a': 1, | ||
const regular = flatulence.unflatten(flattened) | ||
// { a: 1, b: { c: 1, d: [ 1, 2, 3 ] } } | ||
// Only unflatten a sub object | ||
@@ -73,0 +72,0 @@ const b = flatulence.unflatten(flattened, 'b') |
@@ -1,1 +0,2 @@ | ||
require('./test') | ||
require('./flatten.test') | ||
require('./unflatten.test') |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22005
19
8
354
74