npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keyleet

v0.3.3

Published

Add, delete and retrieve keys from objects

Downloads

5

Readme

Keyleet

Library to add, delete and retrieve keys from objects.

Build Status

Installation

npm install keyleet

Usage

This module exports one object containing three functions: deleteKeys, addKeys and accessValueByString, example of using this library is shown below.

AddKeys & DeleteKeys

The documentation for the deleteKeys & addKeys method is basically the same, the examples apply to both functions but deleteKeys is used as an example.

var keyleet = require('keyleet');

var object = {
    data: {
        name: 'Testy Test',
        firstName: 'Testy',
        lastName: 'Test'
    }
};

var modifiedObject = keyleet.deleteKeys(object, {data: {name: ''}}); // Returns object not containing name attribute in the data array anymore.

Things to note

First parameter passed to the function should always be an object literal for now.

The second object describes which keys you would like removed from the object. These can be four of the following options:

  • String in the form of: key.nestedkey. Example for the above object would be: 'data.name'

  • Object containing the keys, example for the above object would be:

var removeKeysObject = {
    data: {
        name: ''
    }
}

The values of these keys don't matter, can be either null or some value.

  • Array containing strings described in number 1. Example would be: ['data.name', 'data.firstName']

  • Array containing objects described in number 2. Example for above object would be:

var arrayOfRemoveKeysObjects = [
    {
        data: {
            name: ''
        }
    },
    {
        data: {
            firstName: ''
        }
    }
]
  • Array containing both strings and object described in number 1 & 2. Example for above object would be:
var mixedArrayOfRemoveKeys = [
    'data.name',
    {
        data: {
            firstName: ''
        }
    },
    'data.lastName'
];

AccessValueByString

If you have an object with several nested keys it can be hard to directly access the values of those nested keys.

This function makes it easy to do so and works as following:

var keyleet = require("keyleet");

var object = {
    data: {
        personalInfo: {
            name: {
                firstName: 'Testy'
                }
        }
    }
};

// Access nested property
var value = keyleet.accessValueByString(object, 'data.personalInfo.name.firstName');

// Access top level key
var dataArray = keyleet.accessValueByString(object, 'data');

// Accessing nested property which doesn't resolve to a single value
var personalInfoArray = keyleet.accessValueByString(object, 'data.personalInfo');