UNPKG

attadux

Version:

Implementation of the redux-modular-ducks, forked from the extensible-duck implementation and extended to include spected validators, state machines, helpers, web workers, effect handling, action multipliers, action enhancers, action throttling/debouncing

121 lines (110 loc) 4.19 kB
import _default16 from 'ramda/src/curry'; import _default15 from 'ramda/src/pathSatisfies'; import _default14 from 'ramda/src/both'; import _default13 from 'ramda/src/anyPass'; import _default12 from 'ramda/src/is'; import _default11 from 'ramda/src/either'; import _default10 from 'ramda/src/allPass'; 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*$/)); /** * 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 = _default10([isNotBlankString, _default11(_default12(Number), _default12(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 = _default13([_default12(Boolean), _default12(Number), _default12(String), _default12(RegExp), _default12(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 = _default14(isPlainObj, _default15(_default10([_default12(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); });