Comparing version 1.4.1 to 1.4.2
// add | ||
/** | ||
* Insert value in an array. | ||
* @param values array | ||
* @param insert value to insert | ||
* @param pos insertion position | ||
* @returns {*} | ||
*/ | ||
module.exports = function(values, insert, pos) { | ||
@@ -3,0 +10,0 @@ if(values == null) { |
var get = require('./get'); | ||
/** | ||
* Get all values from an array if they are an object with a "keyName" attribute. | ||
* @param values array | ||
* @param keyName object attribute name | ||
* @returns {Array} | ||
*/ | ||
function all(values, keyName) { | ||
@@ -4,0 +10,0 @@ if(values instanceof Array) { |
@@ -0,1 +1,7 @@ | ||
/** | ||
* Merge two arrays. | ||
* @param values array 1 | ||
* @param values2 array 2 | ||
* @returns {Array} | ||
*/ | ||
function and(values, values2) { | ||
@@ -2,0 +8,0 @@ var results = []; |
@@ -0,3 +1,11 @@ | ||
/** | ||
* Assert methods. | ||
*/ | ||
var Assert = (function() { | ||
function Assert() {} | ||
/** | ||
* Assert that the expression is not null and not empty otherwise it throws an exception. | ||
* @param expr Expression | ||
* @param msg Error message | ||
*/ | ||
Assert.prototype.isDefined = function(expr, msg) { | ||
@@ -4,0 +12,0 @@ if(expr == null || expr == '') { |
var get = require('./get'); | ||
var unique = require('./unique'); | ||
/** | ||
* Select values from an array or an object if they have the attribute value. | ||
* - array : | ||
* - by( [{a:1,b:1},{a:2,b:2}], "a", 1 ) => [{a:1,b:1}] | ||
* - by( [{a:1,b:1},{a:2,b:2}], "a", 11 ) => [] | ||
* - by( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) => [{o1:{a:1,b:1}}] | ||
* - by( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) => [{o1:{a:1,b:1}}] | ||
* - object : | ||
* - by( {o:{a:1,b:1}}, "a", 1 ) => [{a:1,b:1}] | ||
* - by( {o:{a:1,b:1}}, "a", 11 ) => [] | ||
* - by( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) => [{o1:{a:1,b:1}}] | ||
* - by( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) => [] | ||
* @param values Array or object | ||
* @param keyName Attribute name | ||
* @param keyValue Attribute value | ||
* @returns {*} | ||
*/ | ||
function by(values, keyName, keyValue) { | ||
@@ -5,0 +22,0 @@ if(values == null) { |
var get = require('./get'); | ||
var unique = require('./unique'); | ||
/** | ||
* Select values from an array or an object if they do not have the attribute value : | ||
* - array : | ||
* - byNot( [{a:1,b:1},{a:2,b:2}], "a", 1 ) => [{a:2,b:2}] | ||
* - byNot( [{a:1,b:1},{a:2,b:2}], "a", 2 ) => [{a:1,b:1}] | ||
* - byNot( [{a:1,b:1},{a:2,b:2}], "a", 11 ) => [{a:1,b:1},{a:2,b:2}] | ||
* - byNot( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) => [{o2:{a:2,b:2}}] | ||
* - byNot( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) => [{o1:{a:1,b:1}},{o2:{a:2,b:2}}] | ||
* - object : | ||
* - byNot( {o:{a:1,b:1}}, "a", 1 ) => [] | ||
* - byNot( {o:{a:1,b:1}}, "a", 2 ) => [{a:1,b:1}] | ||
* - byNot( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) => [{o2:{a:2,b:2}}] | ||
* - byNot( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) => [{o1:{a:1,b:1}},{o2:{a:2,b:2}}] | ||
* @param values Array or object | ||
* @param keyName Attribute name | ||
* @param keyValue Attribute value | ||
* @returns {*} | ||
*/ | ||
function byNot(values, keyName, keyValue) { | ||
@@ -5,0 +23,0 @@ if(values == null) { |
@@ -0,1 +1,10 @@ | ||
/** | ||
* Concatenate string array values. | ||
* @param values String array values | ||
* @param separator Separator between each values | ||
* @param prefix Prefix added before each value | ||
* @param suffix Suffix added after each value | ||
* @param func (not mandatory) Function to transform each value | ||
* @returns {string} | ||
*/ | ||
var concat = function(values, separator, prefix, suffix, func) { | ||
@@ -2,0 +11,0 @@ var result = ""; |
// each | ||
/** | ||
* Call function for each object or array values. | ||
* @param values Array or object values | ||
* @param func Function to apply with for an array "func(value, index)" and for an object "func(value, key)" | ||
*/ | ||
module.exports = function(values, func) { | ||
@@ -10,3 +15,3 @@ if(values == null) { | ||
for(var i=0; i<length; i++) { | ||
func(values[i]); | ||
func(values[i], i); | ||
} | ||
@@ -13,0 +18,0 @@ } |
var has = require("./has"); | ||
/** | ||
* Return array values which have this attribute value | ||
* - array : | ||
* - has( [{a:1,b:1},{a:2,b:2}], "a", 2 ) => {a:2,b:2} | ||
* - has( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "a", 2 ) => {o2:{a:2,b:2}} | ||
* @param values Array values | ||
* @param keyName attribute name | ||
* @param keyValue attribute value | ||
* @returns {Array} | ||
*/ | ||
var filter = function(values, keyName, keyValue) { | ||
@@ -4,0 +14,0 @@ if(values instanceof Array) { |
@@ -0,1 +1,8 @@ | ||
/** | ||
* Get object or sub-object attribute value : | ||
* get( {o1:{o2:{o3:{a:1}}}}, "o1.o2.o3.a") => 1 | ||
* @param obj Object | ||
* @param keyName Attribute name | ||
* @returns {*} | ||
*/ | ||
function get(obj, keyName) { | ||
@@ -2,0 +9,0 @@ if(obj == null || keyName == null) { |
var get = require('./get'); | ||
/** | ||
* Return true if array values or object values has this attribute value : | ||
* - array : | ||
* - has( [{a:1,b:1},{a:2,b:2}], "a", 1 ) => true | ||
* - has( [{a:1,b:1},{a:2,b:2}], "a", 11 ) => false | ||
* - has( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) => true | ||
* - has( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) => false | ||
* - object : | ||
* - has( {o:{a:1,b:1}}, "a", 1 ) => true | ||
* - has( {o:{a:1,b:1}}, "a", 11 ) => false | ||
* - has( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) => true | ||
* - has( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) => false | ||
* @param values Array values or Object values | ||
* @param keyName | ||
* @param keyValue | ||
* @returns {boolean} | ||
*/ | ||
var has = function(values, keyName, keyValue) { | ||
@@ -4,0 +21,0 @@ if(values == null) { |
{ | ||
"name": "gutil", | ||
"description": "GUtil", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "licenses": [ |
@@ -6,2 +6,47 @@ gutil | ||
- get : Get object or sub-object attribute value : | ||
```js | ||
get( {o1:{o2:{o3:{a:1}}}}, "o1.o2.o3.a") // => 1 | ||
``` | ||
- has : Return true if array values or object values has this attribute value : | ||
```js | ||
// array | ||
has( [{a:1,b:1},{a:2,b:2}], "a", 1 ) // => true | ||
has( [{a:1,b:1},{a:2,b:2}], "a", 11 ) // => false | ||
has( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) // => true | ||
has( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) // => false | ||
// object | ||
has( {o:{a:1,b:1}}, "a", 1 ) // => true | ||
has( {o:{a:1,b:1}}, "a", 11 ) // => false | ||
has( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) // => true | ||
has( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) // => false | ||
``` | ||
- by : Select values from an array or an object if they have the attribute value. | ||
```js | ||
// array | ||
by( [{a:1,b:1},{a:2,b:2}], "a", 1 ) // => [{a:1,b:1}] | ||
by( [{a:1,b:1},{a:2,b:2}], "a", 11 ) // => [] | ||
by( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) // => [{o1:{a:1,b:1}}] | ||
by( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) // => [{o1:{a:1,b:1}}] | ||
// object | ||
by( {o:{a:1,b:1}}, "a", 1 ) // => [{a:1,b:1}] | ||
by( {o:{a:1,b:1}}, "a", 11 ) // => [] | ||
by( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) // => [{o1:{a:1,b:1}}] | ||
by( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) // => [] | ||
``` | ||
- byNot : Select values from an array or an object if they do not have the attribute value : | ||
```js | ||
// array | ||
byNot( [{a:1,b:1},{a:2,b:2}], "a", 1 ) // => [{a:2,b:2}] | ||
byNot( [{a:1,b:1},{a:2,b:2}], "a", 2 ) // => [{a:1,b:1}] | ||
byNot( [{a:1,b:1},{a:2,b:2}], "a", 11 ) // => [{a:1,b:1},{a:2,b:2}] | ||
byNot( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 1 ) // => [{o2:{a:2,b:2}}] | ||
byNot( [{o1:{a:1,b:1}},{o2:{a:2,b:2}}], "o1.a", 11 ) // => [{o1:{a:1,b:1}},{o2:{a:2,b:2}}] | ||
// object | ||
byNot( {o:{a:1,b:1}}, "a", 1 ) // => [] | ||
byNot( {o:{a:1,b:1}}, "a", 2 ) // => [{a:1,b:1}] | ||
byNot( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 1 ) // => [{o2:{a:2,b:2}}] | ||
byNot( {o:{o1:{a:1,b:1},o2:{a:2,b:2}}}, "o1.a", 11 ) // => [{o1:{a:1,b:1}},{o2:{a:2,b:2}}] | ||
``` | ||
- add : insert value in an array | ||
@@ -11,9 +56,5 @@ - all | ||
- Assert | ||
- by | ||
- byNot | ||
- concat | ||
- each | ||
- filter | ||
- get | ||
- has | ||
- log | ||
@@ -20,0 +61,0 @@ - oneBy |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41355
31
1208
76