Crisp.PathJS
is a DSL Language to finde nodes in JavaScript Objects with focus of FRD (find, rule and deliver)
var myObject = Crisp; // find first node of pathmyObject; // 'B' // find all nodes of path optional asynchronousmyObject;// logs:// success: B// success: C// complete: [ { data: 'B' }, { data: 'C' } ] // check of path exists in objectmyObject; // true
Index Table
Getting Started
Server-Nodes
Use Node Package Manager (npm) to install crisp-path
for Node.js and io.js
$ npm install crisp-path
// use package;
or use the OpenCrisp UtilJS wraper
$ npm install crisp-util
// use package;
Web-Clients
Use Bower to install crisp-path
for Browsers APP's and other front-end workflows.
$ bower install crisp-path
<!-- use package -->
or use the OpenCrisp UtilJS wraper
$ bower install crisp-util
<!-- use package -->
Development
Use Git to clone Crisp.PathJS from GitHub to develop the repository with Grunt
# Clone:
$ git clone https://github.com/OpenCrisp/Crisp.PathJS.git
# Build: test, concat, test, minify, test
$ grunt
# Test: original sourcecode for developer (included in build)
$ grunt t
# Run all test-scripts on Unix
$ sh grunt-tests.sh
Usage
How to use Crisp.PathJS
with JavaScript.
Crisp.definePath()
How to use Crisp.definePath( object )
module.
var myObject = a: 'A' b: 'B' ; // initialice path property functions on myObjectCrisp; // find first node of path stringmyObject; // 'A'myObject; // 'B'myObject; // 'A'
Crisp.utilCreate()
How to use Crisp.utilCreate( option )
with util.path
namespace.
// create object with `util.path` namespacevar myObject = Crisp; // find first node of path stringmyObject; // 'A'myObject; // 'B'myObject; // 'A'
PathJS function
.pathNode()
Hot to use .pathNode( path OR option )
on myObject
.
// find first node of path stringmyObject; // 'B' // or with option.path stringmyObject; // 'B'
path (pathNode)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
// find first node of path stringmyObject; // 'A'myObject; // 'B'myObject; // 'A'
option.path (pathNode)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
// find first node of option.path stringmyObject; // 'A'myObject; // 'B'myObject; // 'A'
option.preset (pathNode)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
// find first node of path stringmyObject;// 'X' myObject;// 'X' myObject;// undefined
.pathFind()
Hot to use .pathFind( option )
on myObject
.
var myObject = Crisp; myObject;console; // logs:// Success: A// Complete: [{"data":"A"}]// End
- option
option.path (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// Complete: [{"data":"A"},{"data":"B"}]// End
option.async (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// End// Complete: [{"data":"A"},{"data":"B"}]
option.success (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// Success: A// Success: B// End
option.complete (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// Complete: [{"data":"A"},{"data":"B"}]// End
option.start (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// Complete: [{"data":"B"}]// End
option.limit (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
myObject;console; // logs:// Complete: [{"data":"A"}]// End
option.self (pathFind)
create
myObject
withCrisp.utilCreate()
or initalice withCrisp.definePath()
.
var myArg = {};myObject;console; // logs:// Complete: true// End
.pathExists()
Hot to use .pathExists( path )
on myObject
.
// check of path string exists in myObjectmyObject; // truemyObject; // truemyObject; // false
Path string examples
with callback of complete output
// ## path// Object.key'a.b:' // [ { data: 'B' } ]'a.b:toString' // [ { data: 'B' } ] 'a:xTo' // [ { data: '{"b":"B","c":"C"}' } ] 'x:' // []'a.x:' // [] // Array.index'g.0.h:' // [ { data: 'H0' } ] // ## xEach// Object.xEach'a.*:' // [ { data: 'B' }, { data: 'C' } ] // Object.xEach reverse'a.^*:' // [ { data: 'C' }, { data: 'B' } ] // Array.xEach'g.*.h:'// [ { data: 'H0' }, { data: 'H1' }, { data: 'H2' }, { data: 'H3' }, { data: 'H4' }, { data: 'H5' } ] // Array.xEach reverse'g.^*.h:'// [ { data: 'H5' }, { data: 'H4' }, { data: 'H3' }, { data: 'H2' }, { data: 'H1' }, { data: 'H0' } ] // ## limit// Object.xEach( start, limit ) start'a.0~1:' // [ { data: 'B' } ] // Object.xEach( start, limit ) end'a.-1:' // [ { data: 'C' } ]'a.-1~1:' // [ { data: 'C' } ] // Object.xEach( start, limit ) limit on Object.length'a.0~10:' // [ { data: 'B' }, { data: 'C' } ]'a.-10~10:' // [ { data: 'B' }, { data: 'C' } ] // Object.xEach( start, limit ) out of range'a.10~10:' // [] // Array.xEach( start, limit ) start'g.0~2.h:' // [ { data: 'H0' }, { data: 'H1' } ] // Array.xEach( start, limit ) start reverse'g.^0~2.h:' // [ { data: 'H5' }, { data: 'H4' } ] // Array.xEach( start, limit ) end'g.-1.h:' // [ { data: 'H5' } ]'g.-1~1.h:' // [ { data: 'H5' } ] // Array.xEach( start, limit ) limit on Array.length'g.0~10.h:''g.-10~10.h:''g.-~.h:'// [ { data: 'H0' }, { data: 'H1' }, { data: 'H2' }, { data: 'H3' }, { data: 'H4' }, { data: 'H5' } ] // Array.xEach( start, limit ) out of range// default range 0~10'g.10~10.h:' // [] // find all with filter'#(h=="H2").i:' // [ { data: 'I2' } ] 'a.#(b=="B").c:' // [ { data: 'C' } ] 'a.#(b=="X").c:' // [] // find all with specific filter'+(!:xType("Array")).#:xTo'// [// { data: '{"a":{"b":"B","c":"C"},"g":[{"h":"H0","i":"I0"},{"h":"H1","i":"I1"},{"h":"H2","i":"I2"},{"h":"H3","i":"I3"},{"h":"H4","i":"I4"},{"h":"H5","i":"I5"}]}' },// { data: '{"b":"B","c":"C"}' },// { data: '"B"' },// { data: '"C"' }// ] // find all with specific filter and second filter'+(!:xType("Array")).#(:xType("field")):' // [ { data: 'B' }, { data: 'C' } ]