New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@panosoft/ramda-utils

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@panosoft/ramda-utils

Utilities built on top of Ramda.

  • 0.1.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.7K
decreased by-1.14%
Maintainers
1
Weekly downloads
 
Created
Source

ramda-utils

Utilities built on top of Ramda.

npm version npm license Travis David npm downloads

Installation

npm install @panosoft/ramda-utils

Usage

var Ru = require('@panosoft/ramda-utils');

API


### applyTo ( obj , fn )

Apply an object to a function

Arguments

  • obj - An object.
  • fn - A function.

Example

var obj = {a: 'a'};
var fn = (obj) => obj.a;
Ru.applyTo(obj, fn) // 'a';

### compareProps ( props , a , b )

Returns a curried comparator function that can be used with R.sort. Supports any number of sort orders (i.e. property1 ascending, property 2 descending, etc.). It also supports type based sorting (i.e. recognizes Date, Number, etc. and sorts them appropriately).

Arguments

  • props - A string or an array of strings used to determine the sort order to apply. Each string signifies a property name to compare. A '+' prefix is used to signify ascending order and a '-' prefix is used to signify descending order.
  • a - A value to compare.
  • b - A value to compare.

Example

var list = [
  { b: true,  n: 10,  s: 'test',  d: new Date('1/1/2015') },
  { b: false, n: -1,  s: 'aaaa',  d: new Date('1/1/2015') },
  { b: true,  n: 12,  s: 'aaaa',  d: new Date('1/1/2015') },
  { b: false, n: 3,   s: 'xyz',   d: new Date('1/1/2000') },
  { b: false, n: 12,  s: 'aaaa',  d: new Date('1/1/2015') }
];
var props = ['-d', '+s', '-n', 'b'];
R.sort(Ru.compareProps(props), list);
/*
  [
    { b: false, n: 12,  s: 'aaaa',  d: new Date('1/1/2015') },
    { b: true,  n: 12,  s: 'aaaa',  d: new Date('1/1/2015') },
    { b: false, n: -1,  s: 'aaaa',  d: new Date('1/1/2015') },
    { b: true,  n: 10,  s: 'test',  d: new Date('1/1/2015') },
    { b: false, n: 3,   s: 'xyz',   d: new Date('1/1/2000') }
  ];
 */

### complementC ( fn )

Returns a curried complement.

Arguments

  • fn - A function.

Example

var fn = (a,b) => b;
fn(null, false) // false;
Ru.complementC(fn)(null)(false) // true;

### defaults ( def , obj )

Creates a new object with the own properties of def merged with the defined own properties of obj.

Any properties of obj that resolve to undefined will be replaced by the corresponding properties in def if they exist. Otherwise, properties that resolve to undefined in both obj and def will be omitted in the returned object.

Arguments

  • def - An object containing default properties.
  • obj - An object to default.

Example

var def = {a: 1, b: 2, c: 3};
var obj = {a: 4, b: undefined};
var defObj = Ru.defaults(def, obj); // { a: 4, b: 2, c: 3 }

### filterObj ( pred , obj )

Filters an object by property.

Arguments

  • pred - A function used to test each object property. It is called with the property value and should return a Boolean.
  • obj - An object to filter.

Example

var obj = {a: true, b: false, c: true};
var pred = (x) => x;
Ru.filterObj(pred, obj) // {a: true, c: true}

### isEmptyC ( fn )

Returns a curried function that tests whether the original function returns a list with zero elements when called.

Arguments

  • fn - A function.

Example

var fn = (a,b) => a+b;
fn('a','b') // 'ab'
fn('','') // ''

Ru.isEmptyC(fn)('a')('b') // false;
Ru.isEmptyC(fn)('')('') // true;

### isNotEmptyC ( fn )

Returns a curried function that tests whether the original function returns a list with elements when called.

Arguments

  • fn - A function.

Example

var fn = (a,b) => a+b;
fn('a','b') // 'ab'
fn('','')   // ''

Ru.isNotEmptyC(fn)('a')('b')  // true;
Ru.isNotEmptyC(fn)('')('')    // false;

### matchGroups ( reg , str )

Applies a Regular Expression to a String and returns the matched groups as an array of arrays.

Arguments

  • reg - A regular expression.
  • str - A string to search.

Example

var str = 'abcd abbbd ab___d';
var reg = /ab(.+?)(d)/g;
Ru.matchGroups(reg, str) // [ [ 'c', 'd'], [ 'bb', 'd' ], ['___', 'd'] ]

### pickValues ( keys , obj )

Picks values from an object using the specified keys. Returns a new array.

Arguments

  • keys - A string or an array of strings corresponding to the keys of values to be picked.
  • obj - An object to pick values from.

Example

var obj = {a: true, b: false, c: true};
var keys = ['b', 'c'];
Ru.pickValues(keys, obj) // [false, true]

### rmap ( obj , fns )

Maps an array of functions to their return values by applying an object to each.

Arguments

  • obj - An object to apply.
  • fns - A function or an array of functions to map.

Example

var obj = {a: 'a', b: 'b'};
var fns = [(obj) => obj.a, (obj) => obj.b];
Ru.rmap(obj, fns) // ['a', 'b']

### subsetOf ( set , sub )

Tests if an array is a subset of another.

Arguments

  • set - An array that defines the complete set.
  • sub - An array to test.

Example

var set = [1, 2, 3, 4];
var sub = [2, 3];
var notSub = [4, 5];
Ru.subsetOf(set, sub)     // true;
Ru.subsetOf(set, notSub)) // false;

### sumProps ( keys , obj )

Returns the sum of the specified properties.

Arguments

  • keys - An array of strings used to determine which properties to sum.
  • obj - An object containing the specified keys.

Example

var obj = {a: 1, b: 2, c: 4};
var keys = ['b', 'c'];
Ru.sumProps(keys, obj)  // 6

### sumColumn ( key , objs )

Return the sum of the specified property across an array of objects.

Arguments

  • key - A string used to determine which property to sum.
  • objs - An object or an array of objects containing the specified key.

Example

var objs = [{a: 1}, {a: 2}, {a: 4}];
var key = 'a';
Ru.sumColumn(key, objs)  // 7

### toNumber ( x )

Converts a value to a Number. Arguments

  • x - A value to convert.

Example

var str = '1';
Ru.toNumber(str) // 1

### toString ( x )

Converts a value to a String.

Arguments

  • x - A value to convert.

Example

var num = 1;
Ru.toString(num) // '1'

### toDate ( x )

Convert a value to a Date.

Arguments

  • x - A value to convert.

Example

var str = '1/1/2000';
Ru.toDate(str)  // new Date(str)

### trace ( msg , x )

Logs a message and value and then returns the value.

Arguments

  • msg - A string message to log.
  • x - A value to log and return.

Example

var msg = 'X:';
var fn = R.compose(R.add(1), Ru.trace(msg), R.add(1));

var result = fn(1);   // stdout: 'X: 3'
console.log(result);  // 3

### zipApply ( fns , objs )

Zips an array of functions and an array of objects into an array of values produced by applying each object to its respective function.

Arguments

  • fns - An array of functions.
  • objs - An array of objects.

Example

var objs = [{a: 'a'}, {b: 'b'}];
var fns = [(obj) => obj.a, (obj) => obj.b];
Ru.zipApply(fns, objs) // ['a', 'b']

FAQs

Package last updated on 18 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc