Coder Social home page Coder Social logo

futil-js's Introduction

futil

Greenkeeper badge npm version dependencies Code Climate Codacy Badge Coverage Status Standard - JavaScript Style Guide

A collection of F(unctional) Util(ities). Resistance is futile.

Mostly, these are generic utilities that could conceivably be part of a library like lodash/fp, but for some reason or other are not.

Version History/Changelog

See our changelog

Installing

npm i -S futil-js

This package requires lodash/fp, so make sure that's available in your app.

API

Function

maybeCall

(fn, a, b) -> fn(a, b) If fn is a function, call the function with the passed-in arguments. Otherwise, return false.

overNone

([f, g]) -> !f(x) && !g(x) Creates a function that checks if none of the predicates return truthy when invoked with the arguments it receives.

Collection

flowMap

...fns:functions -> map:function Runs a map function that runs a flow of the functions passed in to this method.

Lodash Conversions

These are conversions of lodash fp methods.

Ins (Rearg False)

getIn, includesIn, pickIn lodash/fp is great, but sometimes the curry order isn't exactly what you want. These methods provide alternative orderings that are sometimes more convenient. The idea of In methods is to name them by convention, so when ever you need a method that actually takes the collection first (e.g. a get where the data is static but the field is dynamic), you can just add In to the end (such as getIn which takes the object first)

Ons (Immutable False)

extendOn, defaultsOn lodash/fp likes to keep things pure, but sometimes JS can get pretty dirty. These methods are alternatives for working with data that--for whatever the use case is--needs to be mutable Any methods that interact with mutable data will use the On convention (as it is some action occuring On some data)

Array

compactJoin

join:string -> data:array -> result:string Joins an array after compacting.

dotJoin

data:array -> result:string Compacts and joins an array with '.'

repeated

data:array -> result:array Returns an array of elements that are repeated in the array.

Object

singleObject

(k, v) -> {k: v} Creates an object with a key and value.

singleObjectE

(v, k) -> {k: v} Flipped version of singleObject.

chunkObject

({a, b}) -> [{a}, {b}] Breaks an object into an array of objects with one key each.

compactObject

Remove properties with falsey values.

Example: ({ a: 1, b: null, c: false }) -> {a:1}

isEmptyObject:

Check if the variable is an empty object ({}).

isNotEmptyObject:

Check if the variable is not an empty object ({}).

stripEmptyObjects

Omit properties whose values are empty objects.

Example: { a:1, b:{}, c:2 } -> {a:1, c:2} (TODO remame to omitEmptyObjects)

compareDeep

Checks if an object's property is equal to a value.

matchesSignature

Returns true if object keys are only elements from signature list. (but does not require all signature keys to be present)

pickInto

TODO

renameProperty

from:string -> to:string: -> target:object -> result:object Rename a property on an object.

Example: renameProperty('a', 'b', {a:1}) -> {b:1)

unwind

Just like mongo's $unwind.

Example: { x:['a','b'], y:1 } -> [{ x:'a', y:1 }, { x:'b', y:1 }]

flattenObject

Flatten an object with the paths for keys.

Example: { a: { b: { c: 1 } } } => { 'a.b.c' : 1 }.

String

parens

'asdf' -> '(asdf)' Wraps a string in parenthesis.

Misc

testRegex

regex -> string -> bool Just like rambda test, creates a function to test a regex on a string.

Math

greaterThanOne

number -> bool Returns true if number is greater than one.

futil-js's People

Contributors

agamemnus avatar daedalus28 avatar frozegnome avatar greenkeeper[bot] avatar kmachado avatar sadasant avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.