Giter Club home page Giter Club logo

Comments (4)

jameswyse avatar jameswyse commented on July 28, 2024

Just ran in to this myself. I'm using unflatten to turn S3 keys in to a tree (by using '/' as a delimiter) and my S3 bucket has keys like 03/09/2014/filename.zip which turns in to { 3: { 9: { 2014: 'filename.zip' } } }

I fixed this by checking opts.object in the getKey function and not casting to Number if it's set:

function getkey(key) {
    var parsedKey = Number(key)

    return (
      opts.object ||
      isNaN(parsedKey) ||
      key.indexOf('.') !== -1
    ) ? key
      : parsedKey
  }

I realize that yes, you can pass {object:true} to unflatten, and it will not automatically assume it's an array, but then you get the opposite behavior. i.e. "Arrays turn into objects".

Does this actually happen though? It looks like unflatten handles this by returning non-Objects immediately:

if (Object.prototype.toString.call(target) !== '[object Object]') {
    return target
}

I'll write some tests to make sure and submit a PR :)

from flat.

timoxley avatar timoxley commented on July 28, 2024

bump

from flat.

joshgillies avatar joshgillies commented on July 28, 2024

Any thoughts on resolving this? Same issue as described in the original issue being experienced over here.

from flat.

twhitbeck avatar twhitbeck commented on July 28, 2024

We're moving off this library because of this issue.
One possible fix: use a different delimiter for arrays.

flatten({ test: ['a', 'b', 'c'] });

could yield

{ 'test[0]': 'a', 'test[1]': 'b', 'test[2]': 'c' }

from flat.

Related Issues (20)

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.