ruddy
Version:
Modularized state-management tools for modern front-end applications. Manage dispatched messages in a clean and predictable way for either small or large scale projects
195 lines (180 loc) • 8.21 kB
JavaScript
import _default17 from 'ramda/src/all';
import _default16 from 'ramda/src/curry';
import _default15 from 'ramda/src/pathSatisfies';
import _default14 from 'ramda/src/anyPass';
import _default13 from 'ramda/src/either';
import _default12 from 'ramda/src/allPass';
import _default11 from 'ramda/src/is';
import _default10 from 'ramda/src/both';
import _default9 from 'ramda/src/not';
import _default8 from 'ramda/src/isEmpty';
import _default7 from 'ramda/src/isNil';
import _default6 from 'ramda/src/complement';
import _default5 from 'ramda/src/defaultTo';
import _default4 from 'ramda/src/path';
import _default3 from 'ramda/src/equals';
import _default2 from 'ramda/src/compose';
import _default from 'ramda/src/test';
/**
* Checks to see if a prop name is an alphanumeric string (plus some symbols
* allowed, like underscores, dashes and dots)
*
* @func
* @sig a -> Boolean
* @param {String} prop A prop name to check for formatting
* @returns {Boolean} whether or not the prop name passed validation
*/
export var isValidPropName = _default(/^(?:[A-Z])([A-Z0-9_\-.]+)([A-Z0-9])$/i);
/**
* Checks to see if a given value is a JavaScript Promise
*
* @func
* @sig * -> Boolean
* @param {*} val A value to check to see if is a Promise
* @returns {Boolean} whether or not the val is a Promise
*/
export var isPromise = _default2(_default3('Promise'), _default4(['constructor', 'name']), _default5(''));
/**
* Checks to see if a given value is an Object
*
* @func
* @sig * -> Boolean
* @param {*} val A value to check for objectishness
* @returns {Boolean} whether or not the val is a plain old JS object
*/
export var isPlainObj = _default2(_default3('Object'), _default4(['constructor', 'name']), _default5(''));
/**
* Checks to make sure a given value isn't null or undefined
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be null / undefined
* @returns {Boolean} whether or not the value was non-nil
*/
export var isNotNil = _default6(_default7);
/**
* Checks to make sure a given value isn't empty
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be empty
* @returns {Boolean} whether or not the value was non-empty
*/
export var isNotEmpty = _default6(_default8);
/**
* Checks to see whether or not a given String is non-blank (one or more chars)
*
* @func
* @sig String -> Boolean
* @param {String} val A String which may or may not be blank
* @returns {Boolean} whether or not a given String is non-blank
*/
export var isNotBlankString = _default2(_default9, _default(/^\s*$/));
/**
* Most of the time, this is what you're looking for when checking a String value:
* - Is it a String?
* - Is it something other than whitespace?
*
* @func
* @sig * -> Boolean
* @param {*} val A value that may or may not be a non-blank String
* @returns {Boolean} Whether or not the value is a non-blank String
*/
export var isGoodString = _default10(_default11(String), isNotBlankString);
/**
* Checks to see whether or not a given value is a non-blank String (one or more chars)
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be a non-blank String
* @returns {Boolean} whether or not a given value is a non-blank String
*/
export var isStringieThingie = _default12([isNotBlankString, _default13(_default11(Number), _default11(String)), isNotNil]);
/**
* Checks to see whether or not a given value is either: Boolean, Number, String, Data, or RegExp
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be "primitive-ish"
* @returns {Boolean} whether or not a given value is "primitive-ish"
*/
export var isPrimitiveish = _default14([_default11(Boolean), _default11(Number), _default11(String), _default11(RegExp), _default11(Date)]);
/**
* Check that action is an object with a "type" prop that is a non-blank string
*
* @func
* @sig * -> Boolean
* @param {*} val A value which may or may not be a Redux action
* @returns {Boolean}
*/
export var isAction = _default10(isPlainObj, _default15(_default12([_default11(String), _default(/\S/)]), ['type']));
/**
* Checks to see if a provided object has a given prop (path)
*
* @func
* @sig [String] -> {k: v} -> Boolean
* @param {String[]} propPath An array of string values representing the nested path to a prop
* @param {Object} obj An object on which a given prop may exist
* @returns {Boolean} whether or not the provided prop path exists on the provided object
*/
export var hasNestedProp = _default16(function (propPath, obj) {
return _default2(isNotNil, _default4(propPath))(obj);
});
/**
* Checks to see if a given value a Function or an Object
* (meant to be transformed into a [Shapey](https://github.com/arizonatribe/shapey) spec Function
*
* @func
* @sig * -> Boolean
* @param {*} val A value to evaluate as a possible pair of predicate (String/RegExp/Function) & transform/effect Function
* @returns {Boolean} whether or not the value is an enhancer
*/
export var isSpecOrFunction = _default14([_default10(_default11(Array), _default17(_default13(_default11(Function), isPlainObj))), isPlainObj, _default11(Function)]);
/**
* Checks to see if a given value is an Enhancer, which means it is an Array
* that has one of the following as its first index:
* - A Regular Expression
* - A String value (not blank; should match some Action's type value)
* - A predicate function (meant to evaluate a criteria on an Action object)
*
* For the second index, it checks to see if it is:
* - An Object (meant to be transformed into a [Shapey](https://github.com/arizonatribe/shapey) spec Function
* - A Function meant to return an Action Object
*
* @func
* @sig * -> Boolean
* @param {*} val A value to evaluate as a possible pair of predicate (String/RegExp/Function) & transform/effect Function
* @param {Object} obj An object on which a given prop may exist
* @returns {Boolean} whether or not the value is a qualifying pre-formed Enhancer
*/
export var isEnhancer = _default12([_default11(Array), _default15(_default14([_default11(RegExp), isGoodString, _default11(Function)]), [0]), _default15(_default13(_default11(Function), isPlainObj), [1])]);
/**
* Checks to see if a given value is an Array that is meant to be turned into an Effect handler,
* which means the first index should be:
* - A Regular Expression
* - A String value (not blank; should match some Action's type value)
* - A predicate function (meant to evaluate a criteria on an Action object)
*
* For the second index, it checks to see if it is:
* - An Object (meant to be transformed into a [Shapey](https://github.com/arizonatribe/shapey) spec Function
* - A Function meant to produce some kind of effect
*
* For the (optional) third index, it checks to see if it is:
* - An Object (meant to be transformed into a [Shapey](https://github.com/arizonatribe/shapey) spec Function
* - A Function meant to return an Action Object when the effect succeeds
* - A String, meant to become the "type" prop on a new Action Object that is
* returned when the effect succeeds
*
* For the (optional) fourth index, it checks to see if it is:
* - An Object (meant to be transformed into a [Shapey](https://github.com/arizonatribe/shapey) spec Function
* - A Function meant to return an Action Object when the effect fails
* - A String, meant to become the "type" prop on a new Action Object that is
* returned when the effect fails
*
* @func
* @sig * -> Boolean
* @param {*} val A value to evaluate as a possible pair of predicate (String/RegExp/Function) & transform/effect Function
* @param {Object} obj An object on which a given prop may exist
* @returns {Boolean} whether or not the value is a qualifying predicate pair
*/
export var isEffect = _default12([_default11(Array), _default15(_default14([_default11(RegExp), isGoodString, _default11(Function)]), [0]), _default15(_default13(_default11(Function), isPlainObj), [1]), _default15(_default14([_default7, isPlainObj, isGoodString, _default11(Function)]), [2]), _default15(_default14([_default7, isPlainObj, isGoodString, _default11(Function)]), [3])]);