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

flatulence

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flatulence - npm Package Compare versions

Comparing version 0.1.10 to 0.1.12

lib/deflate.js

39

lib/flatulence.js

@@ -0,38 +1,15 @@

const inflate = require('./inflate')
const deflate = require('./deflate')
const flatulence = {
toFlatArray() {
throw new Error('not implemented yet')
},
toFlatArray() { throw new Error('not implemented yet') },
flatten(subject, prefix = '', result = {}) {
deflate,
if(subject !== null && typeof subject === 'object') {
for(var key in subject) {
flatulence.flatten(
subject[key],
extendPrefix(prefix, key, Array.isArray(subject)),
result
)
}
return result
}
result[removeTrailingDot(prefix)] = subject
return result
}
inflate,
}
const removeTrailingDot = prefix => {
const lastIdx = prefix.length - 1
return prefix.charAt(lastIdx) === '.'
? prefix.substring(0, lastIdx)
: prefix
}
const extendPrefix = (prefix, key, isArrayElement = false) => {
return isArrayElement
? removeTrailingDot(prefix) + '[' + key + '].'
: prefix + key + '.'
}

@@ -42,2 +19,4 @@

module.exports = flatulence
{
"name": "flatulence",
"version": "0.1.10",
"description": "Flatten objects and arrays so that each key is the full path to a primitive value. Paths are lodash-compatible.",
"version": "0.1.12",
"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 JSON objects again.",
"main": "index.js",

@@ -19,4 +19,5 @@ "scripts": {

"assert": "^1.4.1",
"lodash": "^4.16.6",
"mocha": "^3.1.2"
}
}

@@ -1,13 +0,25 @@

const mocha = require('mocha')
const assert = require('assert')
const fl = require('../lib')
const data = require('./data')
const fp = require('lodash/fp')
describe('flatulence', () => {
describe('#flatten()', () => {
describe('#deflate()', () => {
it('should flatten object', () => {
const flattened = fl.flatten(data)
console.log(flattened)
const flattened = fl.deflate(data)
assert.equal(flattened['array[0][1]'], 1)
})
})
describe('#inflate()', () => {
it('should reverse flattened object to an inflated one', () => {
const flattened = fl.deflate(data)
const inflated = fl.inflate(flattened, 'cc')
assert.deepEqual(data.cc, inflated)
})
})
})
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