Skip to content

Commit

Permalink
Docs: Update examples with expected output
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Stramel committed Feb 22, 2018
1 parent d953bd9 commit 8e157c2
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions example.js
Expand Up @@ -19,22 +19,62 @@ console.log(dotty.exists(object, ["a", "b", "z"])); // false
console.log(dotty.get(object, "a.b.x")); // "y"
console.log(dotty.get(object, ["a", "b", "x"])); // "y"
console.log(dotty.get(object, "a.b.z")); // undefined
console.log(dotty.get(object, ["a", "b", "z"])); // undefine
console.log(dotty.get(object, "a.b.z.z")); // undefined
console.log(dotty.get(object, ["a", "b", "z"])); // undefined

dotty.put(object, "a.b.hello", "hi");
dotty.put(object, ["a", "c", "yo"], "sup");

console.log(dotty.search(object, "a.b.*"));
console.log(dotty.search(object, ["a", "b", "*"]));
console.log(dotty.search(object, "a.*.x"));
console.log(dotty.search(object, ["a", "*", "x"]));
console.log(dotty.search(object, ["a", "*", /..+/]));
console.log(dotty.search(object, "a.b.*")); // ["y", "hi"]
console.log(dotty.search(object, ["a", "b", "*"])); // ["y", "hi"]
console.log(dotty.search(object, "a.*.x")); // ["y", "z"]
console.log(dotty.search(object, ["a", "*", "x"])); // ["y", "z"]
console.log(dotty.search(object, ["a", "*", /..+/])); // ["hi", "sup"]

console.log(dotty.remove(object, "a.b.x"));
console.log(dotty.remove(object, "a.b.y"));

console.log(dotty.deepKeys(object));
/**
[
[ 'a' ],
[ 'a', 'b' ],
[ 'a', 'b', 'hello' ],
[ 'a', 'c' ],
[ 'a', 'c', 'x' ],
[ 'a', 'c', 'yo' ]
]
*/

console.log(dotty.deepKeys(object, {leavesOnly: true}));
/**
[
[ 'a', 'b', 'hello' ],
[ 'a', 'c', 'x' ],
[ 'a', 'c', 'yo' ]
]
*/

console.log(dotty.deepKeys(object, {leavesOnly: true, asStrings: true}));
/**
[
'a.b.hello',
'a.c.x',
'a.c.yo'
]
*/

console.log(object);
/**
{
a: {
b: {
hello: "hi"
},
c: {
x: "z',
yo: 'sup'
}
}
}
*/

0 comments on commit 8e157c2

Please sign in to comment.