diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..642e69de4 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +nodejs 10.24.1 +python 2.7.18 3.10.5 \ No newline at end of file diff --git a/bin/docs.sh b/bin/docs.sh new file mode 100755 index 000000000..e23ec3981 --- /dev/null +++ b/bin/docs.sh @@ -0,0 +1,40 @@ +#!/usr/bin/bash + +set -e + +function main() +{ + local section="$1" + + case $section in + predicates) + generate_predicates;; + *) + echo "usage: ./bin/docs.sh
";; + esac +} + +function generate_predicates() +{ + local section=$1 + + local cmd='file="${0}" && \ + grep "$(basename ${file%.*}) ::" "$file" | \ + sed -E "s/\s*\/\*\* (.*) :: (.*) \*\//| [\`\1\`][\1] | \`\2\` | \`crocks\/predicates\/\1\` |/"' + + local predicates=$(find "./src/predicates/" \ + -name "*.js" \ + -not -name "*.spec.js}" \ + -exec bash -c "$cmd" {} \;) + + local core=$(find "./src/core/" \ + -name "*.js" \ + -not -name "*.spec.js}" \ + -exec bash -c "$cmd" {} \;) + + local manualAppend='| [`propPathEq`][propPathEq] | `[ String | Number ] -> a -> Object -> Boolean` | `crocks/predicates/propPathEq` |\n| [`propPathSatisfies`][propPathSatisfies] | `[ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propPathSatisfies` |' + + echo -e "${predicates}\n${core}\n${manualAppend}" | sort +} + +main "$@" diff --git a/docs/src/pages/docs/functions/index.md b/docs/src/pages/docs/functions/index.md index 3bf828864..84e4d0d35 100644 --- a/docs/src/pages/docs/functions/index.md +++ b/docs/src/pages/docs/functions/index.md @@ -128,6 +128,61 @@ type: `Pred a` and vice-versa | [`unless`][unless] | `(a -> Boolean) -> (a -> a) -> a -> a` | `crocks/logic/unless` | | [`when`][when] | `(a -> Boolean) -> (a -> a) -> a -> a` | `crocks/logic/when` | +## Predicate + +| Function | Signature | Location | +|:---|:---|:---| +| [`hasProp`][hasProp] | `(String or Integer) -> a -> Boolean` | `crocks/predicates/hasProp` | +| [`hasPropPath`][hasPropPath] | `[ String or Integer ] -> a -> Boolean` | `crocks/predicates/hasPropPath` | +| [`hasProps`][hasProps] | `Foldable f => f (String or Integer) -> a -> Boolean` | `crocks/predicates/hasProps` | +| [`isAlternative`][isAlternative] | `a -> Boolean` | `crocks/predicates/isAlternative` | +| [`isAlt`][isAlt] | `a -> Boolean` | `crocks/predicates/isAlt` | +| [`isApplicative`][isApplicative] | `a -> Boolean` | `crocks/predicates/isApplicative` | +| [`isApply`][isApply] | `a -> Boolean` | `crocks/predicates/isApply` | +| [`isArray`][isArray] | `a -> Boolean` | `crocks/predicates/isArray` | +| [`isBichain`][isBichain] | `a -> Boolean` | `crocks/predicates/isBichain` | +| [`isBifunctor`][isBifunctor] | `a -> Boolean` | `crocks/predicates/isBifunctor` | +| [`isBoolean`][isBoolean] | `a -> Boolean` | `crocks/predicates/isBoolean` | +| [`isCategory`][isCategory] | `a -> Boolean` | `crocks/predicates/isCategory` | +| [`isChain`][isChain] | `a -> Boolean` | `crocks/predicates/isChain` | +| [`isContravariant`][isContravariant] | `a -> Boolean` | `crocks/predicates/isContravariant` | +| [`isDate`][isDate] | `a -> Boolean` | `crocks/predicates/isDate` | +| [`isDefined`][isDefined] | `a -> Boolean` | `crocks/predicates/isDefined` | +| [`isEmpty`][isEmpty] | `a -> Boolean` | `crocks/predicates/isEmpty` | +| [`isExtend`][isExtend] | `a -> Boolean` | `crocks/predicates/isExtend` | +| [`isFalse`][isFalse] | `a -> Boolean` | `crocks/predicates/isFalse` | +| [`isFalsy`][isFalsy] | `a -> Boolean` | `crocks/predicates/isFalsy` | +| [`isFoldable`][isFoldable] | `a -> Boolean` | `crocks/predicates/isFoldable` | +| [`isFunction`][isFunction] | `a -> Boolean` | `crocks/predicates/isFunction` | +| [`isFunctor`][isFunctor] | `a -> Boolean` | `crocks/predicates/isFunctor` | +| [`isInteger`][isInteger] | `a -> Boolean` | `crocks/predicates/isInteger` | +| [`isIterable`][isIterable] | `a -> Boolean` | `crocks/predicates/isIterable` | +| [`isMap`][isMap] | `a -> Boolean` | `crocks/predicates/isMap` | +| [`isMonad`][isMonad] | `a -> Boolean` | `crocks/predicates/isMonad` | +| [`isMonoid`][isMonoid] | `a -> Boolean` | `crocks/predicates/isMonoid` | +| [`isNil`][isNil] | `a -> Boolean` | `crocks/predicates/isNil` | +| [`isNumber`][isNumber] | `a -> Boolean` | `crocks/predicates/isNumber` | +| [`isObject`][isObject] | `a -> Boolean` | `crocks/predicates/isObject` | +| [`isPlus`][isPlus] | `a -> Boolean` | `crocks/predicates/isPlus` | +| [`isProfunctor`][isProfunctor] | `a -> Boolean` | `crocks/predicates/isProfunctor` | +| [`isPromise`][isPromise] | `a -> Boolean` | `crocks/predicates/isPromise` | +| [`isSame`][isSame] | `(a, b) -> Boolean` | `crocks/predicates/isSame` | +| [`isSameType`][isSameType] | `Container m => (m, m) -> Boolean` | `crocks/predicates/isSameType` | +| [`isSemigroup`][isSemigroup] | `a -> Boolean` | `crocks/predicates/isSemigroup` | +| [`isSemigroupoid`][isSemigroupoid] | `a -> Boolean` | `crocks/predicates/isSemigroupoid` | +| [`isSetoid`][isSetoid] | `a -> Boolean` | `crocks/predicates/isSetoid` | +| [`isString`][isString] | `a -> Boolean` | `crocks/predicates/isString` | +| [`isSymbol`][isSymbol] | `a -> Boolean` | `crocks/predicates/isSymbol` | +| [`isTraversable`][isTraversable] | `a -> Boolean` | `crocks/predicates/isTraversable` | +| [`isTrue`][isTrue] | `a -> Boolean` | `crocks/predicates/isTrue` | +| [`isTruthy`][isTruthy] | `a -> Boolean` | `crocks/predicates/isTruthy` | +| [`pathEq`][pathEq] | `[ String or Number ] -> a -> Object -> Boolean` | `crocks/predicates/pathEq` | +| [`pathSatisfies`][pathSatisfies] | `[ (String or Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/pathSatisfies` | +| [`propEq`][propEq] | `(String or Integer) -> a -> b -> Boolean` | `crocks/predicates/propEq` | +| [`propPathEq`][propPathEq] | `[ String or Number ] -> a -> Object -> Boolean` | `crocks/predicates/propPathEq` | +| [`propPathSatisfies`][propPathSatisfies] | `[ (String or Integer) ] -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propPathSatisfies` | +| [`propSatisfies`][propSatisfies] | `(String or Integer) -> (a -> Boolean) -> b -> Boolean` | `crocks/predicates/propSatisfies` | + [monoids]: ../monoids/index.html [crocks]: ../crocks/index.html [pred]: ../crocks/Pred.html @@ -199,3 +254,54 @@ type: `Pred a` and vice-versa [or]: logic-functions.html#or [unless]: logic-functions.html#unless [when]: logic-functions.html#when + +[hasProp]: predicate-functions.html +[hasPropPath]: predicate-functions.html +[hasProps]: predicate-functions.html +[isAlternative]: predicate-functions.html +[isAlt]: predicate-functions.html +[isApplicative]: predicate-functions.html +[isApply]: predicate-functions.html +[isArray]: predicate-functions.html +[isBichain]: predicate-functions.html +[isBifunctor]: predicate-functions.html +[isBoolean]: predicate-functions.html +[isCategory]: predicate-functions.html +[isChain]: predicate-functions.html +[isContravariant]: predicate-functions.html +[isDate]: predicate-functions.html +[isDefined]: predicate-functions.html +[isEmpty]: predicate-functions.html +[isExtend]: predicate-functions.html +[isFalse]: predicate-functions.html +[isFalsy]: predicate-functions.html +[isFoldable]: predicate-functions.html +[isFunction]: predicate-functions.html +[isFunctor]: predicate-functions.html +[isInteger]: predicate-functions.html +[isIterable]: predicate-functions.html +[isMap]: predicate-functions.html +[isMonad]: predicate-functions.html +[isMonoid]: predicate-functions.html +[isNil]: predicate-functions.html +[isNumber]: predicate-functions.html +[isObject]: predicate-functions.html +[isPlus]: predicate-functions.html +[isProfunctor]: predicate-functions.html +[isPromise]: predicate-functions.html +[isSame]: predicate-functions.html +[isSameType]: predicate-functions.html +[isSemigroup]: predicate-functions.html +[isSemigroupoid]: predicate-functions.html +[isSetoid]: predicate-functions.html +[isString]: predicate-functions.html +[isSymbol]: predicate-functions.html +[isTraversable]: predicate-functions.html +[isTrue]: predicate-functions.html +[isTruthy]: predicate-functions.html +[pathEq]: predicate-functions.html +[pathSatisfies]: predicate-functions.html +[propEq]: predicate-functions.html +[propPathEq]: predicate-functions.html +[propPathSatisfies]: predicate-functions.html +[propSatisfies]: predicate-functions.html diff --git a/src/core/isArray.js b/src/core/isArray.js index c2c7999eb..cfac6005f 100644 --- a/src/core/isArray.js +++ b/src/core/isArray.js @@ -1,6 +1,7 @@ /** @license ISC License (c) copyright 2016 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ +/** isArray :: a -> Boolean */ function isArray(x) { return Array.isArray(x) } diff --git a/src/core/isDefined.js b/src/core/isDefined.js index 2ebbd9283..db6d79279 100644 --- a/src/core/isDefined.js +++ b/src/core/isDefined.js @@ -1,6 +1,7 @@ /** @license ISC License (c) copyright 2017 original and current authors */ /** @author Ian Hofmann-Hicks (evil) */ +/** isDefined :: a -> Boolean */ function isDefined(x) { return x !== undefined } diff --git a/src/core/isEmpty.js b/src/core/isEmpty.js index 52c184bbc..8d8c6c042 100644 --- a/src/core/isEmpty.js +++ b/src/core/isEmpty.js @@ -5,6 +5,7 @@ const isMonoid = require('./isMonoid') const equals = require('./equals') const fl = require('./flNames') +/** isEmpty :: a -> Boolean */ function isEmpty(x) { if(isMonoid(x)) { const empty = x.constructor[fl['empty']] || x.constructor['empty'] || x['empty'] diff --git a/src/core/isIterable.js b/src/core/isIterable.js index cb2cf0070..02d387307 100644 --- a/src/core/isIterable.js +++ b/src/core/isIterable.js @@ -4,6 +4,7 @@ const isFunction = require('./isFunction') const isNil = require('./isNil') +/** isIterable :: a -> Boolean */ function isIterable(iterable) { return !isNil(iterable) && isFunction(iterable[Symbol.iterator]) } diff --git a/src/core/isMap.js b/src/core/isMap.js index f10679b93..0de4788ff 100644 --- a/src/core/isMap.js +++ b/src/core/isMap.js @@ -1,6 +1,7 @@ /** @license ISC License (c) copyright 2019 original and current authors */ /** @author Benny Powers (bennypowers) */ +/** isMap :: a -> Boolean */ function isMap(x) { return x instanceof Map } diff --git a/src/predicates/pathSatisfies.js b/src/predicates/pathSatisfies.js index d201c127f..1122d3bae 100644 --- a/src/predicates/pathSatisfies.js +++ b/src/predicates/pathSatisfies.js @@ -14,8 +14,8 @@ const err = name => `${name}: First argument must be an Array of non-empty Strings or Integers` function fn(name) { - // pathSatisfies: [ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean - // pathSatisfies: [ (String | Integer) ] -> Pred a -> b -> Boolean + /** pathSatisfies :: [ (String | Integer) ] -> (a -> Boolean) -> b -> Boolean */ + /** pathSatisfies :: [ (String | Integer) ] -> Pred a -> b -> Boolean */ function pathSatisfies(keys, pred, x) { if(!isArray(keys)) { throw new TypeError(err(name)) diff --git a/src/predicates/propEq.js b/src/predicates/propEq.js index ceebf840a..2acea64fc 100644 --- a/src/predicates/propEq.js +++ b/src/predicates/propEq.js @@ -9,7 +9,7 @@ const isInteger = require('../core/isInteger') const isNil = require('../core/isNil') const isString = require('../core/isString') -// propEq: (String | Integer) -> a -> b -> Boolean +/** propEq :: (String | Integer) -> a -> b -> Boolean */ function propEq(key, value, x) { if(!(isString(key) && !isEmpty(key) || isInteger(key))) { throw new TypeError( diff --git a/src/predicates/propSatisfies.js b/src/predicates/propSatisfies.js index 6c3412184..4525f8647 100644 --- a/src/predicates/propSatisfies.js +++ b/src/predicates/propSatisfies.js @@ -9,8 +9,8 @@ const isPredOrFunc = require('../core/isPredOrFunc') const isString = require('../core/isString') const predOrFunc = require('../core/predOrFunc') -// propSatisfies: (String | Integer) -> (a -> Boolean) -> b -> Boolean -// propSatisfies: (String | Integer) -> Pred a -> b -> Boolean +/** propSatisfies :: (String | Integer) -> (a -> Boolean) -> b -> Boolean */ +/** propSatisfies :: (String | Integer) -> Pred a -> b -> Boolean */ function propSatisfies(key, pred, x) { if(!(isString(key) && !isEmpty(key) || isInteger(key))) { throw new TypeError(