Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

WhyThat/ramda-helpers

Repository files navigation

ramda-helpers

This a library that expose some ramda helpers

Installation

With yarn

yarn add ramda-helpers

Whit npm

npm install --save ramda-helpers

USage

You have to import helpers like any other ES6 module

import ramdahelper from 'ramda-helpers'

ramdaHelper.isNilOrEmpty(null) //=> true

API

compact

returns a list without falsy values

Parameters

  • Array

Examples

compact(['', 'test', 0, undefined, null])  //=> ['test']

Returns Array

descOrderBy

Sort desc a list of nested object by a prop

Parameters

Examples

descOrderBy('a', [{ a:1, b:2 }, { a:2, b:1 }])  //=> [{ a:2, b:1 }, { a:1, b:2 }]

Returns Array

getPath

Retrieve the value at the given path

Parameters

Examples

getPath('a.b.c', { a: { b : { c : 'value' } } })  //=> 'value'
getPath(['a', 'b', 'c'], { a: { b : { c : 'value' } } })  //=> 'value'
getPath(['a', 'c', 'd'], { a: { b : { c : 'value' } } })  //=> undefined

Returns any The data at path

isArray

Returns true if prop is a Array

Parameters

  • value any

Examples

isArray(() => {}) //=> false
isArray({}) //=> false
isArray([]) //=> true

Returns Boolean

isFunction

Returns true if prop is a function

Parameters

  • value any

Examples

isFunction({}) //=> false
isFunction(() => {}) //=> true

Returns Boolean

isNilOrEmpty

  • See: isPathSatisfied if you want to test nested object

Test if value is NilOrEmpty

Parameters

  • val any

Examples

isNilOrEmpty([]) //=> true
isNilOrEmpty({}) //=> true
isNilOrEmpty('') //=> true
isNilOrEmpty(null) //=> true
isNilOrEmpty(false) //=> false
isNilOrEmpty('test') //=> false
isNilOrEmpty(['test']) //=> false
isNilOrEmpty({ a: 1 }) //=> false

Returns bool

isNotArray

  • See: isArray

Returns true if prop is not an array

Parameters

  • value any

Examples

isNotArray(() => {}) //=> true
isNotArray({}) //=> true
isNotArray([]) //=> false

Returns Boolean

isNotFunction

  • See: isFunction

Returns true if prop is not a function

Parameters

  • value any

Examples

isNotFunction(() => {}) //=> false
isNotFunction({}) //=> true

Returns Boolean

isNotPlainObject

  • See: isPlainObject

Returns true if prop is not a plainObject

Parameters

  • value any

Examples

isNotPlainObject({}) //=> false
isNotPlainObject(() => {}) //=> true
isNotPlainObject([]) //=> true

Returns Boolean

isPathSatisfied

Returns true if the specified object property at given path isSet @see isSet returns false otherwise

Parameters

Examples

isPathSatisfied('a.b.c', { a: { b: { c: 'c'} } }) //=> true
isPathSatisfied(['a', 'b', 'c'], { a: { b: { c: 'c'} } }) //=> true
isPathSatisfied('a.c.d', { a: { b: { c: 'c'} } }) //=> false

Returns Boolean

isPlainObject

Returns true if prop is a plainObject

Parameters

  • value any

Examples

isPlainObject({}) //=> true
isPlainObject(() => {}) //=> false
isPlainObject([]) //=> false

Returns Boolean

isSet

  • See: isNilOrEmpty

Returns true for value that are defined and not empty, false otherwise

Parameters

  • value any

Examples

isSet([]) //=> false
isSet({}) //=> false
isSet('') //=> false
isSet(null) //=> false
isSet(false) //=> true
isSet('test') //=> true
isSet(['test']) //=> true
isSet({ a: 1 }) //=> true

Returns Boolean

maxByKey

Returns the object which have the greater value by the key, * otherwise returns default object

Parameters

  • defaultObject any
  • Array

Examples

maxByKey('a', { a: 0 }, [{ a: 6 }, { a: 5 }]) //=> { a: 6 }

Returns any

renameKeysBy

Returns objects with all keys renamed by the predicate (recursivly)

Parameters

Examples

renameByKey(str => `prefix_${str}`, { test: 'test' })
   //=> { prefix_test: 'test' }

Returns Object

strToCamelCase

Returns string in camelCase style

Parameters

Examples

strToCamelCase('') //=> ''
strToCamelCase('camelCaseString')  //=> 'camelCaseString'
strToCamelCase('StrWithUpper')  //=> 'strWithUpper'
strToCamelCase('str-with-dashes')  //=> 'strWithDashes'
strToCamelCase('Iam@-random/string')  //=> 'iamRandomString'

Returns string

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published