All Projects → doowb → stringify-keys

doowb / stringify-keys

Licence: MIT license
Build an array of key paths from an object.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to stringify-keys

expand-hash
Recursively expands property keys with dot-notation into objects.
Stars: ✭ 25 (+38.89%)
Mutual labels:  object, objects, dot-notation, keys, expand
omit-empty
Recursively omit empty properties from an object. Omits empty objects, arrays, strings, and optionally zero. Similar results to what you would expect with `compact` for arrays.
Stars: ✭ 71 (+294.44%)
Mutual labels:  object, keys
has-value
Returns true if a value exists, false if empty. Works with deeply nested values using object paths.
Stars: ✭ 27 (+50%)
Mutual labels:  object, dot-notation
glob-object
Filter an object using glob patterns and dot notation.
Stars: ✭ 25 (+38.89%)
Mutual labels:  object, dot-notation
object-keys
Object.keys shim
Stars: ✭ 41 (+127.78%)
Mutual labels:  object, keys
rename-keys
Modify/rename the keys of the own enumerable properties of an object.
Stars: ✭ 28 (+55.56%)
Mutual labels:  object, keys
get
🚚 A really small and type-safe (requires TypeScript >= 4.1.3) function, that gets a nested value from an object using a path string (like "a.b[0].d"). If value is 'undefined' or unreachable returns the placeholder instead.
Stars: ✭ 13 (-27.78%)
Mutual labels:  object, dot-notation
Forgjs
ForgJs is a javascript lightweight object validator. Go check the Quick start section and start coding with love
Stars: ✭ 1,687 (+9272.22%)
Mutual labels:  object
Yolo person detect
person detect based on yolov3 with several Python scripts
Stars: ✭ 212 (+1077.78%)
Mutual labels:  object
Box
Python dictionaries with advanced dot notation access
Stars: ✭ 1,804 (+9922.22%)
Mutual labels:  object
What The Filter
A visual playground to JavaScript array & object transformations.
Stars: ✭ 128 (+611.11%)
Mutual labels:  object
Node Console Probe
Inspect JavaScript object methods and properties in the console.
Stars: ✭ 139 (+672.22%)
Mutual labels:  object
Typy
Minimal JavaScript type checking library
Stars: ✭ 215 (+1094.44%)
Mutual labels:  object
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (+655.56%)
Mutual labels:  object
path-dsl-rs
A Rust utility DSL and macro to help construct and modify Paths.
Stars: ✭ 19 (+5.56%)
Mutual labels:  paths
Springimpl v2.0
模拟Spring框架,实现IOC,AOP
Stars: ✭ 132 (+633.33%)
Mutual labels:  object
is-valid-glob
Return true if a value is a valid glob pattern string, or array of glob patterns.
Stars: ✭ 21 (+16.67%)
Mutual labels:  paths
datoteka
A filesystem toolset and storage implementation for Clojure.
Stars: ✭ 59 (+227.78%)
Mutual labels:  paths
Get Value
Use property paths (`a.b.c`) get a nested value from an object.
Stars: ✭ 194 (+977.78%)
Mutual labels:  object
Object Oriented Programming Using Python
Python is a multi-paradigm programming language. Meaning, it supports different programming approach. One of the popular approach to solve a programming problem is by creating objects. This is known as Object-Oriented Programming (OOP).
Stars: ✭ 183 (+916.67%)
Mutual labels:  object

stringify-keys NPM version NPM monthly downloads NPM total downloads Linux Build Status

Build an array of key paths from an object.

Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save stringify-keys

See the Release History for changes.

Usage

const stringify = require('stringify-keys');

let obj = { a: 'a', b: { c: { d: { e: 'f' } } } };
console.log(stringify(obj));
//=> [ 'a', 'b.c.d.e' ]

Include values in the result:

console.log(stringify(obj, { values: true }));
//=> { a: 'a', 'b.c.d.e': 'f' }

Keys with dots are automatically escaped with backslashes (this can be customized):

let obj = { 'a.b.c': { d: 'e' } };
console.log(stringify(obj));
//=> [ 'a\\.b\\.c.d' ]

console.log(stringify(obj, { values: true }));
//=> { 'a\\.b\\.c.d': 'e' }

Objects with arrays return the array indices as part of the paths:

let obj = { a: 'a', b: [{ c: { d: 'e' } }, { f: { g: 'h' } }] };

console.log(stringify(obj));
//=> [ 'a', 'b.0.c.d', 'b.1.f.g' ]

console.log(stringify(obj, { values: true }));
//=> { a: 'a', 'b.0.c.d': 'e', 'b.1.f.g': 'h' }

Options

options.separator

Type: string

Default: .

Custom separator to use for creating object paths (a.b.c):

Example

let obj = { 'a.b.c': { d: 'e' } };
console.log(stringify(obj, { separator: '/' }));
//=>  [ 'a.b.c/d' ]

console.log(stringify(obj, { separator: '/', values: true }));
//=>  { 'a.b.c/d': 'e' }

options.escape

Type: function

Default: adds \\ before dots

Custom function to use for escaping keys.

Example

let obj = { 'a.b.c': { d: 'e' } };
let escape = str => str.split('.').join('/');

console.log(stringify(obj, { escape }));
//=>  [ 'a/b/c.d' ]

console.log(stringify(obj, { escape, values: true }));
//=>  { 'a/b/c.d': 'e' }

Release History

v3.0

  • Redundant (parent) keys are no longer included in the output. Thus { a: { b: 'c' } } now returns ['a.b'] instead of ['a', 'a.b'].

v2.0

  • Added support for traversing into arrays.

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

Commits Contributor
19 doowb
17 jonschlinkert
1 contra

Author

Brian Woodward

License

Copyright © 2019, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on January 22, 2019.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].