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

174 lines (130 loc) 6.01 kB
'use strict'; exports.__esModule = true; exports.hasNestedProp = exports.isAction = exports.isPrimitiveish = exports.isStringieThingie = exports.isNotBlankString = exports.isNotEmpty = exports.isNotNil = exports.isPlainObj = exports.isPromise = exports.isValidPropName = undefined; var _curry = require('ramda/src/curry'); var _curry2 = _interopRequireDefault(_curry); var _pathSatisfies = require('ramda/src/pathSatisfies'); var _pathSatisfies2 = _interopRequireDefault(_pathSatisfies); var _both = require('ramda/src/both'); var _both2 = _interopRequireDefault(_both); var _anyPass = require('ramda/src/anyPass'); var _anyPass2 = _interopRequireDefault(_anyPass); var _is = require('ramda/src/is'); var _is2 = _interopRequireDefault(_is); var _either = require('ramda/src/either'); var _either2 = _interopRequireDefault(_either); var _allPass = require('ramda/src/allPass'); var _allPass2 = _interopRequireDefault(_allPass); var _not = require('ramda/src/not'); var _not2 = _interopRequireDefault(_not); var _isEmpty = require('ramda/src/isEmpty'); var _isEmpty2 = _interopRequireDefault(_isEmpty); var _isNil = require('ramda/src/isNil'); var _isNil2 = _interopRequireDefault(_isNil); var _complement = require('ramda/src/complement'); var _complement2 = _interopRequireDefault(_complement); var _defaultTo = require('ramda/src/defaultTo'); var _defaultTo2 = _interopRequireDefault(_defaultTo); var _path = require('ramda/src/path'); var _path2 = _interopRequireDefault(_path); var _equals = require('ramda/src/equals'); var _equals2 = _interopRequireDefault(_equals); var _compose = require('ramda/src/compose'); var _compose2 = _interopRequireDefault(_compose); var _test = require('ramda/src/test'); var _test2 = _interopRequireDefault(_test); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } /** * 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 */ var isValidPropName = exports.isValidPropName = (0, _test2['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 */ var isPromise = exports.isPromise = (0, _compose2['default'])((0, _equals2['default'])('Promise'), (0, _path2['default'])(['constructor', 'name']), (0, _defaultTo2['default'])('')); /** * 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 */ var isPlainObj = exports.isPlainObj = (0, _compose2['default'])((0, _equals2['default'])('Object'), (0, _path2['default'])(['constructor', 'name']), (0, _defaultTo2['default'])('')); /** * 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 */ var isNotNil = exports.isNotNil = (0, _complement2['default'])(_isNil2['default']); /** * 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 */ var isNotEmpty = exports.isNotEmpty = (0, _complement2['default'])(_isEmpty2['default']); /** * 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 */ var isNotBlankString = exports.isNotBlankString = (0, _compose2['default'])(_not2['default'], (0, _test2['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 */ var isStringieThingie = exports.isStringieThingie = (0, _allPass2['default'])([isNotBlankString, (0, _either2['default'])((0, _is2['default'])(Number), (0, _is2['default'])(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" */ var isPrimitiveish = exports.isPrimitiveish = (0, _anyPass2['default'])([(0, _is2['default'])(Boolean), (0, _is2['default'])(Number), (0, _is2['default'])(String), (0, _is2['default'])(RegExp), (0, _is2['default'])(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} */ var isAction = exports.isAction = (0, _both2['default'])(isPlainObj, (0, _pathSatisfies2['default'])((0, _allPass2['default'])([(0, _is2['default'])(String), (0, _test2['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 */ var hasNestedProp = exports.hasNestedProp = (0, _curry2['default'])(function (propPath, obj) { return (0, _compose2['default'])(isNotNil, (0, _path2['default'])(propPath))(obj); });