1.0.2 • Published 4 years ago
deepest-walk v1.0.2
deepest-walk
The Deepest JSON Object Walking Library
Traverse and Modify Arrays, Objects, Numbers, Strings, and Substrings.
why is it the deepest?
There are many great object walking libraries. However, I'm not aware of any other library that will traverse substrings within the strings found in a JSON Object.
install
npm install deepest-walktypes
- array
- object
- array-item-string
- array-item-substring
- object-key-string
- object-key-substring
- object-value-string
- object-value-substring
- undefined
- null
- number
usage
basic usage
const walk = require("deepest-walk");
const data = [
{ name: 'George Washington' },
{ name: 'John Adams' }
];
const callback = ({ data }) => console.log(data);
walk({ data, callback, types: ["object-value-string"] });This will log:
George Washington
John Adamsbreaking on words
Set split_strings_on to " " to break on words
const walk = require("deepest-walk");
const data = [
{ name: 'George Washington' },
{ name: 'John Adams' }
];
const callback = ({ data }) => console.log(data);
walk({ data, callback, types: ["object-value-substring"], split_strings_on: " " });This will log:
George
Washington
John
Adamsmodifying words
The following capitalizes all the strings
const walk = require("deepest-walk");
const data = [
{ name: 'George Washington' },
{ name: 'John Adams' }
];
const callback = ({ data, mod, type }) => {
if (typeof data === "string") {
mod(data.toUpperCase());
}
};
walk({ data, callback });Data will be:
[
{ NAME: 'GEORGE WASHINGTON' },
{ NAME: 'JOHN ADAMS' }
];