
Security News
pnpm 10.16 Adds New Setting for Delayed Dependency Updates
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
isschematools
Advanced tools
This pack contains various tools to work with JavaScript objects. It is created to help you avoid monotonous work such as extract data fields from JS object, transform values(trim, substring, replace, and etc..) and validate object schema fields. The idea to create these tools came after long work with MeteorJS & MongoDB.
npm install isschematools
This pack of the three following modules:
matchTraverse
& traverse
functions are based on some variation of BFS algorithm, and they do not use recursion
This module has the following methods:
var t = require('isschematools');
t.traverse(someObject, callback);
The first param should be an object. The second param should be a callback function which will be invoked on each node of object
/*
* var t = ISSchemaTools; //in browser
*/
var t = require('isschematools');
var someObj = {
prop1: 'Some data',
prop2: 'Some other data',
prop3: {
prop1: [
{
insideProp1Prop3: 'Data'
}
]
}
};
t.traverse(someObj, function iterator(value, key, type, parentNode, isCircular) {
console.log(value);
});
// RESULT:
// 'Some data'
// 'Some other data'
// {prop1: ...}
// [{insideProp1Prop3: ...}]
// {insideProp1Prop3: ...}
// 'Data'
Where:
Object
or Array
Object
or Array
//for object
var object = {
node1 : {
node2: 'value'
}
};
//path for value in node2 will be ['node1', 'node2'];
/*
* var t = ISSchemaTools; //in browser
*/
var t = require('isschematools');
t.matchTraverse(someObject, pattern);
The first param is an object for traverse
.
The second param should be a pattern that describes expected structure of an object.
matchTraverse
allows to traverse an object using special pattern.
Pattern should describe desired structure of object. Each end node of pattern should be a Vertex or Rule. Rule can contain additional info about end node.
/*
* var t = ISSchemaTools; //in browser
*/
var t = require('isschematools');
var pattern = {
name: t.vertex(),
surname: t.vertex(),
nested: {
nested: {
value: t.vertex()
}
}
};
/*
* var t = ISSchemaTools; //in browser
*/
var t = require('isschematools');
var model = {
name: 'Sam',
surname: 'Wartington',
contact: {
isPrimary: true,
city: null,
phones: ['+000 11 000 22 22'],
address: [{
street: 'Calouss',
building: 9,
room: 10
}]
}
};
var pattern = {
name: t.vertex(),
surname: t.vertex(),
contact: {
city: t.vertex(),
phones: [t.vertex()],
address: [{
street: t.vertex(),
building: t.vertex(),
room: t.vertex()
}]
}
};
//returns array of nodes which are defined by pattern
var nodeList = t.matchTraverse(model, pattern);
var cleanNodeList = nodeList.filter(function (node) {
return !(node.value === undefined || node.value === null);
});
var result = cleanNodeList.map(function (node) { return node.value; });
/*
result -> ['Sam', 'Wartington', '+000 11 000 22 22', 9, 10, 'Calouss']
*/
/*
node has following structure:
* value: value of processed node,
* key: property name of processed node,
* level - level of object (root level = 1),
* path - array which consists of property keys from root object to current node,
* pattern - pattern describes current node (Vertex means empty pattern type)
*/
result = t.build(nodeList);
/*
result -> {
name: 'Sam',
surname: 'Wartington',
contact: {
phones: ['+000 11 000 22 22'],
address: [{
street: 'Calouss',
building: 9,
room: 10
}]
}
}
*/
FAQs
Package for Validate, Transform, and Clean object by Schemes
The npm package isschematools receives a total of 1 weekly downloads. As such, isschematools popularity was classified as not popular.
We found that isschematools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm's new minimumReleaseAge setting delays package updates to prevent supply chain attacks, with other tools like Taze and NCU following suit.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.