Coder Social home page Coder Social logo

key-del's People

Contributors

miktam avatar sanchan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

key-del's Issues

Support for (nested) arrays

Would be nice to have support for keys to remove inside of (nested) arrays as well since arrays are also valid parts of a JSON object.

Example:

let data = {
    "myKey1": 123,
    "myKey2": true,
    "myKey3": {
        "myKey4": "foo",
        "myKey5": [
            {
                "myKey1": 456,
                "myKey6": null
            }
        ]
    }
};

let keyDel = require("key-del");
keyDel(data, "myKey1");

Result should be...

{
    "myKey2": true,
    "myKey3": {
        "myKey4": "foo",
        "myKey5": [
            {
                "myKey6": null
            }
        ]
    }
}

...but is...

{
    "myKey2": true,
    "myKey3": {
        "myKey4": "foo",
        "myKey5": [
            {
                "myKey1": 456,
                "myKey6": null
            }
        ]
    }
}

Problem with Javascript objects with Mongo ObjectId

Hi,

I have a JSON object coming from Mongo:
{ "_id" : ObjectId("54a12e61c77c3ae01a84dba5"),
"user" : "demo",
"status" : "approved"
}
If I run:
return_obj = deleteKey(obj, fields);
where var fields = ["status"];

I get the following return_obj:
{ "_id": {
"_bsontype": "ObjectID",
"id": "U\ Ù�Þ�^��¶©�"
},
"user" : "demo"
}

Why the nested level limitation?

I got a deep object and need to delete a prop 5 levels deep. This is apparently "not supported" yet. How come? It's just recursion?

Delete nested keys by full path

It would be nice if we could delete keys from nested objects by their full path (in case the key is named the same in several different nested objects but you only want to delete some of them), i.e.:

var originalObject = {
one: 1,
two: 2,
three: {
nestedOne: 3,
nestedTwo: 4
},
four: {
nestedOne: 5,
nestedTwo: 6
}
}
var result = deleteKey(originalObject, ['one', 'three.nestedOne']) or like
var result = deleteKey(originalObject, ['one', '[three][nestedOne]')

TypeError: Cannot convert undefined or null to object

While trying to delete a nested key, I am getting:

c:\node\project\node_modules\key-del\index.js:60
delete nestedObjectRef[lastAttribute];
^
TypeError: Cannot convert undefined or null to object
at c:\node\project\node_modules\key-del\index.js:60:34
at Array.forEach (native)
at deleteKeysFromObject (c:\node\project\node_modules\key-del\index.js:43:16)
at c:\node\project\node_modules\key-del\index.js:64:33
at Array.forEach (native)
at deleteKeysFromObject (c:\node\project\node_modules\key-del\index.js:43:16)
at c:\node\project\routes\v1\profile.js:229:58
at c:\node\project\node_modules\async\lib\async.js:254:17
at done (c:\node\project\node_modules\async\lib\async.js:135:19)
at c:\node\project\node_modules\async\lib\async.js:32:16

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.