tieup
v0.0.3
Published
simple query for building relation between two list
Downloads
2
Readme
TieUp
simple query for building relation between two list.
'use strict';
let tieup = require('tieup');
let colors = 'red,green'.split(',');
let fruits = 'apple,raspberry,kiwi,cherry,limes'.split(',');
//repeater operator
console.log(tieup.select(colors,'1*3,2*2'));
// => [ [ 'red', 'red', 'red' ], [ 'green', 'green' ] ]
//grouping brackets
console.log(tieup.select(fruits,'[1,2,4],[3,5]'));
// => [ [ 'apple', 'raspberry', 'cherry' ], [ 'kiwi', 'limes' ] ]
//range operator
console.log(tieup.select(fruits,'1..5'));
// => [ 'apple', 'raspberry', 'kiwi', 'cherry', 'limes' ]
console.log(tieup.select(fruits,'1..5,1..3'));
// => [ [ 'apple', 'raspberry', 'kiwi', 'cherry', 'limes' ], [ 'apple', 'raspberry', 'kiwi' ] ]
//join operation of two array
console.log(tieup.join(colors,fruits,'1*3,2*2','[1,2,4],[3,5]'));
// => [ [ 'red', 'apple' ],
// [ 'red', 'raspberry' ],
// [ 'red', 'cherry' ],
// [ 'green', 'kiwi' ],
// [ 'green', 'limes' ] ]
API Reference
1. select
Description : it is used to select array elements according given query.
Usage :
let list = ['A', 'B', 'C', 'D'];
console.log(tieup.select(list, '1..4'));
// => ['A', 'B', 'C', 'D']
console.log(tieup.select(list, '4..1'));
// => [ 'D', 'C', 'B', 'A' ]
console.log(tieup.select(list, '1*3,2*2'));
// => [['A', 'A', 'A'], ['B', 'B']]
console.log(tieup.select(list, '[1*3,2*2]'));
// => ['A', 'A', 'A', 'B', 'B']
// OR
console.log(tieup.ungroup(tieup.select(list,'1*3,2*2')));
// => ['A', 'A', 'A', 'B', 'B']
Syntax : select(list, query, [offset]);
Returns : array
2. join
Description : create relation between two list using query.
Usage :
let list1 = ['A', 'B', 'C', 'D'];
let list2 = ['a', 'b', 'c', 'd'];
console.log(tieup.join(list1, list2, '1..4', '1..4'));
// => [ [ 'A', 'a' ], [ 'B', 'b' ], [ 'C', 'c' ], [ 'D', 'd' ] ]
console.log(tieup.join(list1, list2, '1*4', '1..4'));
// => [ [ 'A', 'a' ], [ 'A', 'b' ], [ 'A', 'c' ], [ 'A', 'd' ] ]
console.log(tieup.join(list1, list2, '1..4', '4..1'));
// => [ [ 'A', 'd' ], [ 'B', 'c' ], [ 'C', 'b' ], [ 'D', 'a' ] ]
Syntax : join(left_list, right_list, left_query, right_query, [offset]);
Returns : array
Arguments :
| Name | Type | Description |
| -------|:-------:| ------------- |
| list | array | Set of values |
| query | string | Create query |
| offset | number | Array index offset for query. default offset = 1
|