@marilyn.m/object-traversal

1.3.8 • Public • Published

API

Create New

Test Schema

const Traversal = require("@marilyn.m/object-traversal");
const data = {
	candies: [
		{
			name: "Twizzler"
		}, 
		{
			name: "Skittles",
			type: "fruity"
		},
		{
			name: "Milky Way",
			type: "chocolate"
		},
	],
	drinks: [
		{
			name: "Champurrado",
			type: "chocolate"
		}
	]
};
const object_traversal = new Traversal(data);

value()

get the final value when finished traversing the data.

find(key:string)

Find the first occurrence of the key.

/*
{ name: "Skittles", type: "fruity" }
*/
object_traversal.find("type").value();

findAll(key:string)

/*
[
	{ name: "Twizzlers" },
	{ name: "Skittles", type: "fruity" },
	{ name: "Milky Way", type: "chocolate" },
	{ name: "Champurrado", type: "chocolate" }
]
*/
object_traversal.findAll("name").value();

findN(key:string, limit:number|null)

/*
[
	{ name: "Twizzlers" },
	{ name: "Skittles", type: "fruity" },
	{ name: "Milky Way", type: "chocolate" },
]
*/
object_traversal.findN("name", 3).value();

get(key:string)

/*
[ "Twizzlers", "Skittles", "Milky Way', "Champurrado" ]
*/
object_traversal.get("name").value();

first(key:string)

/*
Twizzlers
*/
object_traversal.first("name").value();

/*
[ { name: "Champurrado", type: "chocolate" } ]
*/
object_traversal.first("drinks").value()

where(key:string)

/*
[
  { name: "Skittles", type: "fruity" },
  { name: "Milky Way", type: "chocolate" },
  { name: "Champurrado", type: "chocolate" }
]
*/
object_traversal.where("type").value()

where(key:string, value:string)

/*
[
  { name: "Milky Way", type: "chocolate" },
  { name: "Champurrado", type: "chocolate" }
]
*/
object_traversal.where("type", "chocolate").value()

where(key:string, value:string, limit:string|null)

/*
[
  { name: "Milky Way", type: "chocolate" },
]
*/
object_traversal.where("type", "chocolate", 1).value()

Package Sidebar

Install

npm i @marilyn.m/object-traversal

Weekly Downloads

0

Version

1.3.8

License

ISC

Unpacked Size

22.4 kB

Total Files

9

Last publish

Collaborators

  • marilynmorales