Git Product home page Git Product logo

safe-flat's People

Contributors

dependabot[bot] avatar dhershman1 avatar greenkeeper[bot] avatar jessie-codes avatar rpartha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

safe-flat's Issues

Bug Report: Seems to skip empty array values

Describe the bug
It seems like safe-flat skips empty arrays within the passed object

To Reproduce
Steps to reproduce the behavior:

  1. Create an object with a key value pair of an empty array
  2. Run object through safe-flat
  3. Console.log output
  4. See no empty arrays were kept

Expected behavior
The key value pair for the empty array should appear in the flattened object

Desktop (please complete the following information):

  • OS: MaxOS Catalina
  • Browser: Node
  • Version: 14.15.3

Additional context
Example:

const { flatten } = require('safe-flat')
const data = {
  a: [],
  b: 1,
  c: {
    d: []
  }
}

console.log(flatten(data)) // => { b: 1 }

Feature Request: Create Unflat Function

Is your feature request related to a problem? Please describe.

This library currently only supports taking a nested object and flattening it. Ideally, it would also have a function that would take a flatten objected and return a nested object.

Describe the solution you'd like

Create a new function, unflatten, with a function signature of (obj, delimiter) which will return a nested version of the object.

Additional context

This will need to be a breaking change as the code exports the flatten function directly. The new version should export an object that has both the unflatten and flatten functions.

Also flattens cats ๐Ÿˆ

Hello!

Did you consider this use case for your library? hughsk/flat#118 What's the motivation behind flattening custom objects? This can give unexpected surprises like property-symbols or strange buffers. Thanks!

Tested on RunKit for v2.0.0:

const { flatten } = require("safe-flat")

class Cat {
  constructor() {
    this.name = 'Cosmonaut';
  }
  meow() {
    console.log('Meow.');
  }
}

result = flatten({
  cat: {
    instance: new Cat(),
  },
});

console.log(result);
console.log(result['cat.instance']?.meow());

Result:

Object {cat.instance.name: "Cosmonaut"}
undefined

See more in hughsk/flat#118.

Feature Request: TypeScript support

Is your feature request related to a problem? Please describe.
I'm trying to use this package with TypeScript, and I could not find types.

Describe the solution you'd like
Have the types bundled with the project as simple declaration files.

Describe alternatives you've considered
Publish types myself to DefinitelyTyped, which I've just done โ€“ DefinitelyTyped/DefinitelyTyped#57468 @jessie-codes would be super useful if you can review it!

Additional context
None.

Bug Report: Won't unflatten 3 level deep nested objects (will display the value as [Object])

Describe the bug
Unflatenning on a JSON that has 3 levels deep nesting objects, will result values to be saved as [Object] instead of the real value

To Reproduce
Run the following example

const delimiter = "."
const data = {
  key1: {
      keyA: 'valueI'
  },
  key2: {
      keyB: 'valueII'
  },
  key3: { a: { b: { c: 2 } } }
}
let x = flatten(data, delimiter)
console.log(`x is:` , x)
let y = unflatten(x, delimiter)
console.log(`y is:` , y)

Expected behavior
The value on y should be:

{
  key1: { keyA: 'valueI' },
  key2: { keyB: 'valueII' },
  key3: { a: { b: { c: 2 } } }
}

What is actually being generated:

{
  key1: { keyA: 'valueI' },
  key2: { keyB: 'valueII' },
  key3: { a: { b: [Object] } }
}

Screenshots
image

Node v17.1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.