0.0.2 • Published 7 years ago

kvobject v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

kvobject

This package adds key/value methods to the Object class.

API

Load the module (NodeJS)

require("kvobject");

Load the module (web browser)

<script src=".../kvobject/index.js"></script>

create an object and fill with data

var obj = Object.create(null);
obj.a = 1;
obj.b = 2;

create an object from other objects

var obj = Object.kvcopy({a:1}, {b:2});

freeze the object and and make it iterable

Object.kvfreeze(obj);

This method throws an error, if the object is already frozen.

An iterator hook is installed, which iterates on the list of entries from Object.entries(). The list is built on the first request, and is cached for other requests.

iterate on all entries

for (var entry of obj)
	console.log(`key [${entry[0]}] value [${entry[1]}]`);

Available after Object.kvfreeze() created the iterator hook.

iterate on selected entries

Object.kvForEach(obj, [prefix,] (key,value) => console.log(`key [${key}] value [${value}]`));

The optional prefix string filters the list.

This method works with non-kvfrozen objects.

get list of entries

for (var entry of Object.kventries(obj [,prefix]))
	console.log(`key [${entry[0]}] value [${entry[1]}]`);

The optional prefix string filters the list.

This method works with non-kvfrozen objects.

ChangeLog

  • 0.0.1 initial release; supports NodeJS 10.x 9.x 8.x 6.x 4.x 0.12.x

•••

0.0.2

7 years ago

0.0.1

7 years ago