Methods
alwaysArray() → {Array}
Returns always an empty array
Parameters:
Type | Description |
---|---|
Any |
- Source:
alwaysObject() → {Object}
Returns always an empty object
Parameters:
Type | Description |
---|---|
Any |
- Source:
alwaysString() → {String}
Returns always an empty string
Parameters:
Type | Description |
---|---|
Any |
- Source:
alwaysZero() → {Array}
Returns always zero
Parameters:
Type | Description |
---|---|
Any |
- Source:
camelCase(str) → {String}
Transform a string to camelCase
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
- Source:
Example
camelCase('My name is Earl'); //'myNameIsEarl'
camelCase('my-name-is-earl'); //'myNameIsEarl'
capitalize(str) → {String}
Capitalizes a string
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
- Source:
castArray() → {Array|undefined}
Forces an argument to be of type Array when is not undefined
Parameters:
Type | Description |
---|---|
* |
- Source:
castFunction() → {function}
Forces an argument to be a function
Parameters:
Type | Description |
---|---|
* |
- Source:
compact(arr) → {Array}
Removes falsy values from an array
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array |
Source array |
- Source:
condAlways(pred, val) → {*}
Executes cond, but returning fixed values, passed as second argument to predicate
Parameters:
Name | Type | Description |
---|---|---|
pred |
Array |
The predicate |
val |
* |
The value to evaluate |
- Source:
Example
const fn = condAlways([
[prop('foo'), 'a'],
[prop('bar'), 'b'],
]);
fn({ foo: true }); // 'a'
fn({ bar: true }); // 'b'
fn({}); // undefined
deburr(str) → {String}
Removes diacritical marks
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Source string |
defaultToArray() → {Any|Array}
Defaults to an empty array
Parameters:
Type | Description |
---|---|
Any |
- Source:
defaultToFalse() → {Any|String}
Defaults to false
Parameters:
Type | Description |
---|---|
Any |
- Source:
defaultToObject() → {Any|Object}
Defaults to an empty object
Parameters:
Type | Description |
---|---|
Any |
- Source:
defaultToString() → {Any|String}
Defaults to an empty string
Parameters:
Type | Description |
---|---|
Any |
- Source:
defaultToTrue() → {Any|String}
Defaults to true
Parameters:
Type | Description |
---|---|
Any |
- Source:
defaultToZero() → {Any|String}
Defaults to zero
Parameters:
Type | Description |
---|---|
Any |
- Source:
ellipsize(maxChars, str) → {String}
Cuts the string and adds an ellipsis (…) when the length is greater than the data provided
Parameters:
Name | Type | Description |
---|---|---|
maxChars |
Number |
The max number of characters allowed |
str |
String |
Received string |
- Source:
Example
ellipsize(9, 'My name is Earl'); //'My name i…'
ellipsize(40)('My name is Earl'); //'My name is Earl'
endsWith(testStr, str) → {Boolean}
Checks if one string is the end of other
Parameters:
Name | Type | Description |
---|---|---|
testStr |
String |
Test string |
str |
String |
String provided |
- Source:
evolveKeys(keysMap, obj) → {Object}
Evolves the keys of the object based on the functions map passed as argument
Parameters:
Name | Type | Description |
---|---|---|
keysMap |
Object |
The map defining the changes |
obj |
Object |
The source object |
- Source:
filterIndexed(fn, arr) → {Array}
Indexed version of filter
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
The function passed to filter, receiving index as second argument |
arr |
Array |
Source array |
- Source:
gteLength(val, list) → {Boolean}
Checks if the first argument is greater than or equal the length of the second argument
Parameters:
Name | Type | Description |
---|---|---|
val |
Number |
The length value |
list |
String | Array |
The list to compare |
- Source:
Example
lengthLt(4, 'foo'); // true
lengthLt(4, ['a', 'b', 'c']); // true
lengthLt(3, 'foo'); // true
gtLength(val, list) → {Boolean}
Checks if the first argument is greater than the length of the second argument
Parameters:
Name | Type | Description |
---|---|---|
val |
Number |
The length value |
list |
String | Array |
The list to compare |
- Source:
hasNot(x, obj) → {Boolean}
Returns true when the object doesn't contain an own property with the name passed
Parameters:
Name | Type | Description |
---|---|---|
x |
String |
The name of the key |
obj |
Object |
The object where to find the key |
hasNot(x, obj) → {Boolean}
Returns true when the object or the prototype chain doesn't contain a property with the specified name
Parameters:
Name | Type | Description |
---|---|---|
x |
String |
The name of the property |
obj |
Object |
The object where to find the property |
- Source:
Example
class Foo {
constructor() {
this.x = 'foo value';
}
}
hasNotIn('bar', Foo); // true
hasNotIn('constructor', Foo); // false
ifElseAlways(pred, trueValue, falseValue) → {function}
Executes ifElse over 2 fixed values, passed as second and third argument
Parameters:
Name | Type | Description |
---|---|---|
pred |
function |
The predicate |
trueValue |
* |
Value returned when pred evaluates true |
falseValue |
* |
Value returned when pred evaluates false |
- Source:
Example
ifElseAlways(prop('foo'), 'a', 'b', { foo: true }); // 'a'
ifElseAlways(prop('foo'), 'a', 'b', { foo: false }); // 'b'
isBetween(min, max, val) → {Boolean}
Checks if the third argument provided is between the first and the second arguments
Parameters:
Name | Type | Description |
---|---|---|
min |
Number |
The min limit |
max |
Number |
The max limit |
val |
Number |
The current value |
- Source:
isEven(val) → {Boolean}
Checks if the number version of the argument provided is even
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
isFalsy(val) → {Boolean}
Checks if the boolean version of the argument provided is false
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
- Source:
Example
isFalsy(undefined); // true
isFalsy(null); // true
isFalsy(0); // true
isFalsy(''); // true
isFalsy(1); // false
isFalsy('a'); // false
isNaN(val) → {Boolean}
Checks if the value type is NaN (Not a number)
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
Example
isNaN(undefined); // false
isNaN(null); // false
isNaN(0); // false
isNaN(''); // false
isNaN(1); // false
isNaN('a'); // false
isNaN(Number('1')); // false
isNaN(Number('a')); // true
isNot(type, val) → {Boolean}
Returns true when the type is not like the one provided
Parameters:
Name | Type | Description |
---|---|---|
type |
* |
The type to avoid |
val |
* |
The value provided |
isNotBetween(min, max, val) → {Boolean}
Checks if the third argument provided is between the first and the second arguments
Parameters:
Name | Type | Description |
---|---|---|
min |
Number |
The min limit |
max |
Number |
The max limit |
val |
Number |
The current value |
- Source:
isNotEmpty(val) → {Boolean}
Complement for isEmpty
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
- Source:
Example
isNotEmpty('a'); // true
isNotEmpty({ a: 'a' }); // true
isNotEmpty(''); // false
isNotEmpty({}); // false
isNotNaN(val) → {Boolean}
Checks if a parsed number is not a number
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
Checks if the value type is not NaN (Not a number) |
- Source:
Example
isNotNaN(undefined); // true
isNotNaN(null); // true
isNotNaN(0); // true
isNotNaN(''); // true
isNotNaN(1); // true
isNotNaN('a'); // true
isNotNaN(Number('a')); // false
isNotNaN(Number('1')); // true
isNotNil(val) → {Boolean}
Complement for isNil
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
- Source:
isOdd(val) → {Boolean}
Checks if the number version of the argument provided is odd
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
isPlainObject(val) → {Boolean}
Checks if the argument provided is a plain object
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
- Source:
Example
const a = { foo: 'bar' };
class B {
constructor(str) {
this.foo = str;
}
}
const c = new B('bar');
isPlainObject(a); // true
isPlainObject(B); // false
isPlainObject(c); // false
isTruthy(val) → {Boolean}
Complement for isFalsy
Parameters:
Name | Type | Description |
---|---|---|
val |
* |
The value provided |
- Source:
Example
isTruthy('a'); // true
isTruthy(1); // true
isTruthy(undefined); // false
isTruthy(0); // false
isTruthy(null); // false
lengthIs(val, list) → {Boolean}
Checks if the length of the second argument equals the first argument
Parameters:
Name | Type | Description |
---|---|---|
val |
Number |
The length value |
list |
String | Array |
The list to compare |
- Source:
list(…arg) → {Array}
Creates a list (array) with the arguments received
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arg |
* |
<repeatable> |
Argument received |
lteLength(val, list) → {Boolean}
Checks if the first argument is less than or equal the length of the second argument
Parameters:
Name | Type | Description |
---|---|---|
val |
Number |
The length value |
list |
String | Array |
The list to compare |
- Source:
Example
lengthLt(2, 'foo'); // true
lengthLt(2, ['a', 'b', 'c']); // true
lengthLt(3, 'foo'); // true
ltLength(val, list) → {Boolean}
Checks if the first argument is less than the length of the second argument
Parameters:
Name | Type | Description |
---|---|---|
val |
Number |
The length value |
list |
String | Array |
The list to compare |
- Source:
mapIndexed(fn, arr) → {Array}
Indexed version of map
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
The function passed to map, receiving index as second argument |
arr |
Array |
Source array |
- Source:
mapKeys(transformation, obj) → {Object}
Maps the keys of the object based on the functions passed as argument
Parameters:
Name | Type | Description |
---|---|---|
transformation |
function |
The transformation to be applied to all the keys |
obj |
Object |
The source object |
- Source:
notEndsWith(testStr, str) → {Boolean}
Complement for endsWith
Parameters:
Name | Type | Description |
---|---|---|
testStr |
String |
Test string |
str |
String |
String provided |
- Source:
notEquals(firstVal, secondVal) → {Boolean}
Complement for equals
Parameters:
Name | Type | Description |
---|---|---|
firstVal |
* |
First Value |
secondVal |
* |
Second Value |
- Source:
notIncludes(searched, list) → {Boolean}
Complement for includes
Parameters:
Name | Type | Description |
---|---|---|
searched |
* |
The value searched |
list |
Array |
The list where to find the value |
- Source:
pad(len, char, str) → {String}
Forces a string to be of n length. If the string is shorter, it will be filled from both sides with the char provided
Parameters:
Name | Type | Description |
---|---|---|
len |
Number | |
char |
String |
The char for filling |
str |
String |
The source string |
padEnd(len, char, str) → {String}
Forces a string to be of n length. If the string is shorter, it will be filled from the end with the char provided
Parameters:
Name | Type | Description |
---|---|---|
len |
Number | |
char |
String |
The char for filling |
str |
String |
The source string |
padStart(len, char, str) → {String}
Forces a string to be of n length. If the string is shorter, it will be filled from the start with the char provided
Parameters:
Name | Type | Description |
---|---|---|
len |
Number | |
char |
String |
The char for filling |
str |
String |
The source string |
pascalCase(str) → {String}
Transform a string to PascalCase
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
- Source:
Example
pascalCase('My name is Earl'); //'MyNameIsEarl'
pascalCase('my-name-is-earl'); //'MyNameIsEarl'
pathNotEq(x, val, obj) → {Boolean}
Complement for pathEq
Parameters:
Name | Type | Description |
---|---|---|
x |
Array |
The path |
val |
* |
The value for comparison |
obj |
Object |
The object where to find the key |
- Source:
Example
pathNotEq(['foo', 'bar'], 'a', { foo: { bar: 'b' } }); // true
pathNotEq(['foo', 'bar'], 'a', { foo: { bar: 'a' } }); // false
propIsFalsy(propName, obj) → {Boolean}
Check if one property is falsy in the object provided as argument
Parameters:
Name | Type | Description |
---|---|---|
propName |
String |
The name of the prop |
obj |
Object |
The object provided |
- Source:
Example
propIsFalsy('a', { b: 1 }); true
propIsFalsy('a', { a: null, b: 1 }); true
propIsFalsy('a', { a: 2, b: 1 }); false
propIsTruthy(propName, obj) → {Boolean}
Check if one property is truthy in the object provided as argument
Parameters:
Name | Type | Description |
---|---|---|
propName |
String |
The name of the prop |
obj |
Object |
The object provided |
- Source:
propNotEq(x, val, obj) → {Boolean}
Complement for propEq
Parameters:
Name | Type | Description |
---|---|---|
x |
String |
The name of the key |
val |
* |
The value for comparison |
obj |
Object |
The object where to find the key |
- Source:
reduceIndexed(fn, arr) → {*}
Indexed version of reduce
Parameters:
Name | Type | Description |
---|---|---|
fn |
function |
The function passed to reduce, receiving index as third argument for the reducer fn |
arr |
Array |
Source array |
- Source:
Example
reduceIndexed((acc, curr, idx) => `${acc}${curr}.${idx},`, '', ['a', 'b', 'c']); // 'a.0,b.1,c.2,'
renameKeys(keysMap, obj) → {Object}
Renames the keys of the object based on the map passed as argument
Parameters:
Name | Type | Description |
---|---|---|
keysMap |
Object |
The map defining the changes |
obj |
Object |
The source object |
- Source:
reverseAppend(list, val) → {Array}
Appends in reverse order
Parameters:
Name | Type | Description |
---|---|---|
list |
Array |
The array where to append |
val |
* |
The item to be prepended |
- Source:
Example
reverseAppend(['f', 'o'], 'o'); // ['f', 'o', 'o']
reverseAppend(['f', 'o'])('o'); //['f', 'o', 'o']
reverseConcat(a, b) → {Array|String}
Concatenates in reverse order
Parameters:
Name | Type | Description |
---|---|---|
a |
Array | String |
The group to be added at the end |
b |
Array | String |
The group to be added at the start |
- Source:
reverseIncludes(list, val) → {Boolean}
Checks if the list supplied as first argument contains the value supplied as second
Parameters:
Name | Type | Description |
---|---|---|
list |
Array | String |
The list where to search |
val |
* |
The value to compare |
- Source:
reversePrepend(list, val) → {Array}
Appends in reverse order
Parameters:
Name | Type | Description |
---|---|---|
list |
Array |
The array where to append |
val |
* |
The item to be prepended |
- Source:
setDerivedProps(specObj, obj) → {Object}
Generates new properties based on calculations over the object provided
Parameters:
Name | Type | Description |
---|---|---|
specObj |
Object |
The object defining the transformations |
obj |
Object |
The source object |
- Source:
slugify(str) → {String}
Transform a string to a slug
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
- Source:
Example
slugify('My name is Earl'); //'my-name-is-earl'
slugify('José Manuel Lucas Muñoz'); //'jose-manuel-lucas-munoz'
snakeCase(str) → {String}
Transform a string to snake_case
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
- Source:
Example
snakeCase('My name is Earl'); //'my_name_is_earl'
snakeCase('José Manuel Lucas Muñoz'); //'jose_manuel_lucas_munoz'
sortByIndexes(indexes, list) → {Array}
Sort items in a list, indicating the new indexes
Parameters:
Name | Type | Description |
---|---|---|
indexes |
Array |
Array with new indexes |
list |
Array |
The list that will be sorter with the new indexes |
- Source:
Example
const indexes = [0,3,2,1,4];
const incIndexes = [3,2,1,4]
const list = ["a", "b", "c", "d", "e"];
sortByIndexes(indexes, list); // ["a", "d", "c", "b", "e"]
sortByIndexes(incIndexes, list); // [undefined, "c", "b", "a", "d"]
strAssocPath(str, val, obj) → {*}
String version of assocPath
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
val |
* |
The value to be setted |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strAssocPath('a.b.c', 'bar', obj); // a.b.c = 'bar'
strAssocPath('a.b.c', 'bar')(obj); // a.b.c = 'bar'
strDissocPath(str, obj) → {*}
String version of dissocPath
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
d: 'bar',
}
}
};
strDissocPath('a.b.c', obj); // { a: { b: { d: 'bar } } }
strHasPath(str, obj) → {Boolean}
String version of hasPath
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strHasPath('a.b.c', obj); // true
strHasPath('a.b.d', obj); // false
strLensPath(str, val, obj) → {*}
String version of lensPath
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
val |
* |
The value to be setted |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
const fooLens = strLensPath('a.b.c');
view(fooLens, obj); // 'foo'
strNotHasPath(str, obj) → {Boolean}
Complement version of strHasPath
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strNotHasPath('a.b.d', obj); // true
strNotHasPath('a.b.c', obj); // false
strPath(str, obj) → {*}
String version of path
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPath('a.b.c', obj); // 'foo'
strPath('a.b.c')(obj); // 'foo'
strPathEq(str, val, obj) → {Boolean}
String version of pathEq
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
val |
* |
Value to compare with |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPathEq('a.b.c', 'foo', obj); // true
strPathEq('a.b.c', 'bar', obj); // false
strPathNotEq(str, val, obj) → {Boolean}
Complement version of strPathEq
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
String representing the path, separated with dots |
val |
* |
The value to compare with |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPathNotEq('a.b.c', 'bar', obj); // true
strPathNotEq('a.b.c', 'foo', obj); // false
strPathNotSatisfies(pred, str, obj) → {Boolean}
Complement version of strPathSatisfies
Parameters:
Name | Type | Description |
---|---|---|
pred |
function |
The predicate |
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPathNotSatisfies(equals('foo'), 'a.b.c', obj); // false
strPathNotSatisfies(isEmpty, 'a.b.c', obj); // true
strPathOr(defaultVal, str, obj) → {*}
String version of pathOr
Parameters:
Name | Type | Description |
---|---|---|
defaultVal |
* |
Default Value |
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPathOr('bar', 'a.b.d', obj); // bar
strPathOr('bar', 'a.b.c', obj); // foo
strPathSatisfies(pred, str, obj) → {Boolean}
String version of pathSatisfies
Parameters:
Name | Type | Description |
---|---|---|
pred |
function |
The predicate |
str |
String |
String representing the path, separated with dots |
obj |
Object |
Received Object |
- Source:
Example
const obj = {
a: {
b: {
c: 'foo',
}
}
};
strPathSatisfies(equals('foo'), 'a.b.c', obj); // true
strPathSatisfies(isEmpty, 'a.b.c', obj); // false
toFixed(decimals, x) → {String}
Converts a number to a string with n decimals
Parameters:
Name | Type | Description |
---|---|---|
decimals |
Number |
The number of decimals |
x |
Number |
The source number |
- Source:
toFixedNumber(decimals, x) → {Number}
Limits a number to have n decimals
Parameters:
Name | Type | Description |
---|---|---|
decimals |
Number |
The number of decimals |
x |
Number |
The source number |
- Source:
toInteger(x) → {Number}
Converts a number to a integer of base 10
Parameters:
Name | Type | Description |
---|---|---|
x |
Number |
The source number |
- Source:
unlessAlways(pred, value, val) → {value|val}
Executes unless with a fixed value
Parameters:
Name | Type | Description |
---|---|---|
pred |
function |
The predicate |
value |
* |
Value returned when pred evaluates true |
val |
* |
The value to evaluate |
- Source:
Example
whenAlways(prop('foo'), 'a', { foo: true }); // 'a'
whenAlways(prop('foo'), 'a', { foo: false }); // { foo: false }
upperSnakeCase(str) → {String}
Transform a string to snake_case
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
- Source:
Example
snakeCase('My name is Earl'); //'MY_NAME_IS_EARL'
snakeCase('José Manuel Lucas Muñoz'); //'JOSE_MANUEL_LUCAS_MUNOZ'
whenAlways(pred, value, val) → {value|val}
Executes when with a fixed value
Parameters:
Name | Type | Description |
---|---|---|
pred |
function |
The predicate |
value |
* |
Value returned when pred evaluates true |
val |
* |
The value to evaluate |
- Source:
Example
whenAlways(prop('foo'), 'a', { foo: true }); // 'a'
whenAlways(prop('foo'), 'a', { foo: false }); // { foo: false }
whereArgs(obj) → {function}
Applies where function over the arguments received
Parameters:
Name | Type | Description |
---|---|---|
obj |
pred |
Object with the predicates, where each key is the index of the argument |
- Source:
withEvolvedArgs(obj, fn) → {function}
Transforms the arguments received applying an evolve over the object passed as argument Then, it executes the function passed as argument
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
Object with the transformations |
fn |
function |
function to be applied |
- Source:
Example
withEvolvedArgs({
0: toUpper,
1: toLower,
}, concat)('Say Hello ', 'To My Little Friend'); // 'SAY HELLO to my little friend'
words(str) → {Array}
Splits an string by the most common symbols
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Received string |
xCond(pred) → {*|undefined}
Replacement for switch It receives an array of arrays of fixed values representing the predicate It returns the value defined in the second position, from the first row where the first position evaluates to true. If no result is found, it returns undefined
Parameters:
Name | Type | Description |
---|---|---|
pred |
* |
The fixed value for predicate |
Example
const a = 3;
const b = 2;
xCond([
[a < 2, '1'],
[b < 1, '2'],
[a === 3, '3'],
[a > 2, '4'],
]); // '3'
xCond([
[a > 4, 'a'],
]); // undefined
xIfElse(pred, trueValue, falseValue) → {function}
Replacement for ternary operator. When the first argument is true, it returns the second argument, otherwise, it returns the third argument.
Parameters:
Name | Type | Description |
---|---|---|
pred |
* |
The fixed value for predicate |
trueValue |
* |
Value returned when pred evaluates true |
falseValue |
* |
Value returned when pred evaluates false |
- Source: