CSS Selector, use css selector to select js object content.
var root = {
a: {
b: {
c:'c-val'
}
}
}
c3s(root).selectOne('b>c');
// get "c-val"
npm install c3s
prop
select property value which name isprop
*
select any property
-
#idVal
select object which contain id、Id or ID property and this property value isidVal
-
.classVal
select object whichconstructor.name
isclassVal
-
[att]
select containatt
property object -
[att=val]
select object which containatt
property and this property value(toString()
) isval
-
[att^=val]
select object which containatt
property and this property value(toString()
) begins withval
-
[att$=val]
select object which containatt
property and this property value(toString()
) ends withval
-
[att*=val]
select object which containatt
property and this property value(toString()
) containsval
-
[att=val i]
case insensitive
-
:regexpTest(arg)
select match regexp'sarg
value -
:equal(arg)
select equalarg
value -
:type(arg)
select type equalarg
value
You can define new pseudo-class in c3s option.pseudoClasses, ex:
c3s(root, {
pseudoClasses: {
newClass: function (
nodeInfo, // current search results, nodeInfo instance
arg, // arguments in selector statement
/* arg2, ... */
) {
/*
return
Truthy, select this node
Falsy, don't select this node
*/
}
}
})
.selectOne(':newClass, :newClass(arg), :newClass("arg1", 3.14)');
-
prop1 prop2
search prop1 property and contain object property, if statement start isn'tCombinator
, prependprop1
=prop1
-
prop1>prop2
search prop1 property -
prop1~prop2
seach prop1 sibling property
create and return Selector instance by paramters
var root = { a : { b: { c: 'target' } } };
c3s(root, {});
Selector instance by paramters
- root: object, search target
- option: object
- pseudoClasses: object, declare new pseudo-class
get value on path
form root
, if path
is not found, return undefined
var root = { a : { b: { c: 'target' } } };
c3s.getByPath(root, 'a/b/c');
// 'target'
return search result
- root: object, search object
- path: string, property path
- delimiter: string, default = '/'
get first match seach statement value and detail in root
var root = { a : { b: { c: 'target' } } };
c3s(root).selectOne('c');
// NodeInfos by 'target'
NodeInfo instance, contains the following parameters:
- node: search result
- path: property path from root to node
- parent: all parents from root to node
- root: object being queried
- input: string, search statement
get all match seach statement values and detail in root
var root = { a : {
b: { c: 'target1' },
c: 'target2'
} };
c3s(root).selectAll('c');
// NodeInfos by 'target1' and 'target2'
Array, contain match value NodeInfo instance
- input: string, search statement
get value on path
form Selector search target, if path
is not found, return undefined
var root = { a : { b: { c: 'target' } } };
c3s(root).getByPath('a/b/c');
// 'target'
return a NodeInfo Instance contain search result
- path: string, property path
- delimiter: string, default = '/'
npm run test
npm run debug