From 390679784af5e0250076cbdd85f1174d4556e8ff Mon Sep 17 00:00:00 2001 From: elycruz <603428+elycruz@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:05:12 -0400 Subject: [PATCH 1/2] #23 - Progress on cleaning up array types. Changed all '**/types/*.ts' references to point to '**/types' (since types will be/may be moved around, as part of this fix makes sense to keep the paths this way going forward to allow for these kind of edits to happen). --- .gitignore | 2 +- packages/fjl-validator-recaptcha/src/index.js | 296 ++++++++++++++++++ packages/fjl/src/function/curry.ts | 2 +- packages/fjl/src/list/breakOnList.ts | 2 +- packages/fjl/src/list/complement.ts | 2 +- packages/fjl/src/list/concat.ts | 2 +- packages/fjl/src/list/cycle.ts | 2 +- packages/fjl/src/list/difference.ts | 2 +- packages/fjl/src/list/dropWhile.ts | 2 +- packages/fjl/src/list/dropWhileEnd.ts | 6 +- packages/fjl/src/list/elemIndices.ts | 4 +- packages/fjl/src/list/filter.ts | 6 +- packages/fjl/src/list/foldl1.ts | 4 +- packages/fjl/src/list/foldr1.ts | 2 +- packages/fjl/src/list/groupBy.ts | 2 +- packages/fjl/src/list/inits.ts | 2 +- packages/fjl/src/list/insert.ts | 2 +- packages/fjl/src/list/insertBy.ts | 2 +- packages/fjl/src/list/intercalate.ts | 2 +- packages/fjl/src/list/intersperse.ts | 2 +- packages/fjl/src/list/isInfixOf.ts | 2 +- packages/fjl/src/list/map.ts | 6 +- packages/fjl/src/list/mapAccumL.ts | 4 +- packages/fjl/src/list/mapAccumR.ts | 4 +- packages/fjl/src/list/partition.ts | 2 +- packages/fjl/src/list/permutations.ts | 2 +- packages/fjl/src/list/span.ts | 4 +- packages/fjl/src/list/splitAt.ts | 2 +- packages/fjl/src/list/takeWhile.ts | 5 +- packages/fjl/src/list/types.ts | 8 +- .../fjl/src/list/utils/findIndexWhereRight.ts | 6 +- .../fjl/src/list/utils/findIndicesWhere.ts | 5 +- packages/fjl/src/list/utils/findWhere.ts | 6 +- .../fjl/src/list/utils/findexIndexWhere.ts | 6 +- packages/fjl/src/list/utils/sliceCopy.ts | 2 +- packages/fjl/src/list/zip.ts | 2 +- packages/fjl/src/list/zipWith.ts | 2 +- packages/fjl/src/platform/README.md | 9 +- packages/fjl/src/platform/object/index.ts | 2 +- packages/fjl/src/platform/slice/index.ts | 4 +- packages/fjl/src/types/README.md | 7 + packages/fjl/src/types/data.ts | 16 +- packages/fjl/src/types/index.ts | 1 + packages/fjl/src/types/list.ts | 22 ++ packages/fjl/tests/list/test-dropWhileEnd.ts | 2 +- packages/fjl/tests/list/test-find.ts | 2 +- packages/fjl/tests/list/test-mapAccumL.ts | 4 +- packages/fjl/tests/list/test-mapAccumR.ts | 4 +- packages/fjl/tests/string/index_test.ts | 2 +- tsconfig.json | 2 +- 50 files changed, 399 insertions(+), 92 deletions(-) create mode 100644 packages/fjl-validator-recaptcha/src/index.js create mode 100644 packages/fjl/src/types/README.md create mode 100644 packages/fjl/src/types/list.ts diff --git a/.gitignore b/.gitignore index beeec994..e3dde27d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,5 @@ # Files *.log -**/src/**/*.js +#**/src/**/*.js **/src/**/*.js.map diff --git a/packages/fjl-validator-recaptcha/src/index.js b/packages/fjl-validator-recaptcha/src/index.js new file mode 100644 index 00000000..3a98f811 --- /dev/null +++ b/packages/fjl-validator-recaptcha/src/index.js @@ -0,0 +1,296 @@ +/** + * Created by elydelacruz on 6/10/16. + * @module fjlValidatorReCaptcha + * @recaptchaVersion v2 + * @reference see below: + * @see https://developers.google.com/recaptcha/docs/ + * @see https://developers.google.com/recaptcha/docs/verify + * @todo Request handlers should be separated out from inlined definitions + */ +import https from 'https'; +import querystring from 'querystring'; +import {getErrorMsgByKey as getErrorMessageByKey, toValidationResult, toValidationOptions} from 'fjl-validator'; +import {assign, assignDeep, isEmpty, curry, flip, defineEnumProps} from 'fjl'; + +export const + + /** + * @memberOf module:fjlValidatorReCaptcha + * @property MISSING_INPUT_SECRET + * @type {string} + */ + MISSING_INPUT_SECRET = 'missing-input-secret', + + /** + * @memberOf module:fjlValidatorReCaptcha + * @property INVALID_INPUT_SECRET + * @type {string} + */ + INVALID_INPUT_SECRET = 'invalid-input-secret', + + /** + * @memberOf module:fjlValidatorReCaptcha + * @property MISSING_INPUT_RESPONSE + * @type {string} + */ + MISSING_INPUT_RESPONSE = 'missing-input-response', + + /** + * @memberOf module:fjlValidatorReCaptcha + * @property INVALID_INPUT_RESPONSE + * @type {string} + */ + INVALID_INPUT_RESPONSE = 'invalid-input-response', + + /** + * @memberOf module:fjlValidatorReCaptcha + * @proerpty BAD_REQUEST + * @type {string} + */ + BAD_REQUEST = 'bad-request', + + /** + * @memberOf module:fjlValidatorReCaptcha + * @property UNKNOWN_ERROR + * @type {string} + */ + UNKNOWN_ERROR = 'unknown-error', + + /** + * Normalizes value object to be tested by `reCaptchaValidator`. + * @function module:fjlValidatorReCaptcha.toReCaptchaTestValue + * @param incoming {Object} - Incoming 'un-normalized' test value object; E.g. `{secret: '', resonse: '', etc...}` + * @param [outgoing={}]{Object} - Optional. Outgoing object to apply enumerable prop getters and setters to. + * @returns {ReCaptchaTestValue} - In the form of `{secret, response, remoteip}`. + * @throws {Error} - If any of `secret`, `response`, or `remoteip` are passed in with values + * containing anything other than values of type String. + */ + toReCaptchaTestValue = (incoming, outgoing = {}) => + assign(defineEnumProps([ + [String, 'secret'], + [String, 'remoteip'], + [String, 'response'] + ], outgoing), incoming), + + /** + * Normalizes value object to be tested by `reCaptchaValidator`. + * @function module:fjlValidatorReCaptcha.toReCaptchaValidatorOptions + * @param options {Object} - Incoming 'un-normalized' test value object; E.g. `{secret: '', resonse: '', etc...}` + * @param [outgoing={}]{Object} - Optional. Outgoing object to apply enumerable prop getters and setters to. + * @returns {ReCaptchaValidatorOptions} - `{requestOptions {Object}, messageTemplates {Object}}`. + * @throws {Error} - If any of the passed object's properties do not match expected types. + */ + toReCaptchaValidatorOptions = (options, outgoing = {}) => + // @note `toValidationOptions` sets getter and setter for 'messageTemplates', 'valueObscured', and `valueObscurer` + assignDeep( + defineEnumProps([[Object, 'requestOptions', {}]], toValidationOptions(outgoing)), + { + requestOptions: { + host: 'www.google.com', + path: '/recaptcha/api/siteverify', + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + } + }, + messageTemplates: { + [MISSING_INPUT_SECRET]: 'The secret parameter is missing.', + [INVALID_INPUT_SECRET]: 'The secret parameter is invalid or malformed.', + [MISSING_INPUT_RESPONSE]: 'The response parameter is missing.', + [INVALID_INPUT_RESPONSE]: 'The response parameter is invalid or malformed.', + [BAD_REQUEST]: 'Bad request', + [UNKNOWN_ERROR]: 'Unknown error.' + } + }, + options || {} + ), + + /** + * Makes request to reCaptchaV2 service using passed in options and test value. + * @function module:fjlValidatorReCaptcha.makeReCaptchaRequest$ + * @param options {ReCaptchaValidatorOptions} + * @param value {ReCaptchaTestValue} + * @param resolve {Function} - Resolve/success callback - Receives validation result object. + * @param reject {Function} - Reject/failure callback - Receives validation result object and errorCodes array. + * @returns {void} + */ + makeReCaptchaRequest$ = (options, value, resolve, reject) => { + const messages = [], + {secret, remoteip, response} = value; + + if (!secret) { + messages.push(getErrorMessageByKey(options, MISSING_INPUT_SECRET, value)); + } + if (!response) { + messages.push(getErrorMessageByKey(options, MISSING_INPUT_RESPONSE, value)); + } + if (messages.length) { + resolve(toValidationResult({result: false, messages})); + return; // Exiting explicitly here due to function being able to be used in callback style (old-style) + } + + const formParams = {secret, remoteip, response}, + {requestOptions} = options, + serializedParams = querystring.stringify(formParams); + + // Set content-length header + requestOptions.headers['Content-Length'] = serializedParams.length; + requestOptions.body = serializedParams; + + // Make request + const validationResult = toValidationResult(), + request = https.request(requestOptions, res => { // handle `response` (`res`) + let body = ''; + res.setEncoding('utf8'); + res.on('data', chunk => { + body += chunk; + }); + res.on('end', () => { + let responseData = JSON.parse(body), + errorCodes = responseData['error-codes'], + hasErrorCodes = !!errorCodes && !!errorCodes.length, + normalizedErrorCodes = hasErrorCodes ? errorCodes.map(x => x.toLowerCase()) : [], + nonEmptyErrorCodes = []; + + // If validation failed (false, null, undefined) + if (!isEmpty(responseData.success)) { + validationResult.result = true; + resolve(validationResult); + return; + } + + if (hasErrorCodes) { + // Add error message(s) + nonEmptyErrorCodes = + normalizedErrorCodes.filter(code => + options.messageTemplates.hasOwnProperty(code)); + + // Get error messages + if (!nonEmptyErrorCodes.length) { + messages.push(getErrorMessageByKey(options, UNKNOWN_ERROR, value)); + } + + // Else add 'unknown error' error message + else { + nonEmptyErrorCodes.forEach(code => + messages.push(getErrorMessageByKey(options, code, value))); + } + } + else { + messages.push(getErrorMessageByKey(options, UNKNOWN_ERROR, value)); + } + + // Set failure results + validationResult.result = false; + validationResult.messages = messages; + resolve(validationResult, nonEmptyErrorCodes); + }); + }); + request.on('error', err => { + messages.push(err); + validationResult.messages = messages; + validationResult.result = false; + reject(validationResult, err); + }); + request.write(serializedParams, 'utf8'); + request.end(); + }, + + /** + * Validates a test value against google's reCaptchaV2 backend validation service; + * @note unlike `makeReCaptchaRequest$` this method validates/normalizes the passed in data objects before making + * the validation request to the backend-validation-service. + * @function module:fjlValidatorReCaptcha.reCaptchaValidator$ + * @param options {ReCaptchaValidatorOptions} + * @param value {ReCaptchaTestValue} + * @param resolve {Function} - Resolve/success callback - Receives validation result object. + * @param reject {Function} - Reject/failure callback - Receives validation result object and errorCodes array. + * @returns {void} + */ + reCaptchaValidator$ = (options, value, resolve, reject) => + makeReCaptchaRequest$( + toReCaptchaValidatorOptions(options), + toReCaptchaTestValue(value), + resolve, reject + ), + + /** + * Validates a test value against reCaptchaV2 backend service; + * @note When a reject occurs it will receive validation result object and `errorCodes` array (which contains + * error code sent back by reCaptcha service. + * @function module:fjlValidatorReCaptcha.reCaptchaIOValidator$ + * @param options {ReCaptchaValidatorOptions} + * @param value {ReCaptchaTestValue} + * @returns {(Promise.|Promise.>)} + */ + reCaptchaIOValidator$ = (options, value) => + (new Promise((resolve, reject) => + reCaptchaValidator$(options, value, resolve, reject)) + ), + + /** + * Curried version of `reCaptchaIOValidator$`. + * @function module:fjlValidatorReCaptcha.reCaptchaIOValidator + * @param options {ReCaptchaValidatorOptions} + * @param value {ReCaptchaTestValue} + * @returns {(Promise.|Promise.>)} + * @curried - Is curried. + */ + reCaptchaIOValidator = curry(reCaptchaIOValidator$), + + /** + * Alias of `reCaptchaIOValidator`. + * @function module:fjlValidatorReCaptcha.reCaptchaValidator + * @param options {ReCaptchaValidatorOptions} + * @param value {ReCaptchaTestValue} + * @returns {(Promise.|Promise.>)} + * @curried - Is curried. + */ + reCaptchaValidator = reCaptchaIOValidator, + + /** + * Same as `reCaptchaIOValidator` though with arguments flipped; + * Takes `value` parameter first and the `options` one second. + * @function module:fjlValidatorReCaptcha.reCaptchaValidatorV2 + * @param value {ReCaptchaTestValue} + * @param options {ReCaptchaValidatorOptions} + * @returns {(Promise.|Promise.>)} + * @curried - Is curried. + */ + reCaptchaValidatorV2 = curry(flip(reCaptchaIOValidator$)); + +/*------------------- + * VIRTUAL TYPES + * @note 'reCaptcha-v2 backend service' is the backend validation service used to validate, from a backend, + * the frontend validation result (for reCaptchaV2). + *-------------------*/ + +/** + * @typedef {Object.} MessageTemplates + * Message Templates object to get error messages from error codes received from the reCaptcha-v2 'backend' service. + */ + +/** + * @typedef {Object.} RequestOptions + * Options used to make request to google's reCaptcha-v2 backend-validation service. + */ + +/** + * @typedef {Object.} ReCaptchaValidatorOptions + * @property requestOptions {RequestOptions} + * @property messageTemplates {MessageTemplates} + */ + +/** + * @typedef {Object.} ReCaptchaTestValue + * @property {String} secret - The 'secret' key sent to the google reCaptcha-v2 backend service. + * @property {String} response - The 'response' string sent to the reCaptcha-v2 backend service. + * @property {String} [remoteip=undefined] - Optional. The 'remoteip' string sent to the reCaptcha-v2 backend-validation service. + */ + +/** + * @typedef {Object.} ValidationResult + * @property {Boolean} result - Result of validators validation (`true` or `false`). + * @property {Array.} messages - Validation failure messages; Reasons why tested value(s) didn't pass validation. + * @type {string} + */ diff --git a/packages/fjl/src/function/curry.ts b/packages/fjl/src/function/curry.ts index 601ee2d2..d8a8e4b1 100644 --- a/packages/fjl/src/function/curry.ts +++ b/packages/fjl/src/function/curry.ts @@ -4,7 +4,7 @@ * @description "Curry strict" and "curry arbitrarily" functions (`curry`, `curryN`). */ -import {Nary} from '../types/arity'; +import {Nary} from '../types'; import {noop} from './noop'; export type Curry1 = (a?: T, ...b: T[]) => Curry1 | T; diff --git a/packages/fjl/src/list/breakOnList.ts b/packages/fjl/src/list/breakOnList.ts index dab8c943..10797d4e 100644 --- a/packages/fjl/src/list/breakOnList.ts +++ b/packages/fjl/src/list/breakOnList.ts @@ -4,7 +4,7 @@ import {findIndexWhere} from "./utils/findexIndexWhere"; import {of} from "../object/of"; import {reverse} from "./reverse"; import {splitAt} from "./splitAt"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; import {sliceFrom} from "./utils/sliceFrom"; import {PredForSlice} from "./types"; diff --git a/packages/fjl/src/list/complement.ts b/packages/fjl/src/list/complement.ts index 5cf31940..89450c7d 100644 --- a/packages/fjl/src/list/complement.ts +++ b/packages/fjl/src/list/complement.ts @@ -2,7 +2,7 @@ import {curry2, CurryOf2} from '../function/curry'; import {reduce} from "./utils/reduce"; import {append} from "./append"; import {difference} from "./difference"; -import {Slice} from '../types/data'; +import {Slice} from '../types'; export type Complement = CurryOf2 diff --git a/packages/fjl/src/list/concat.ts b/packages/fjl/src/list/concat.ts index c89e5824..a44a8e33 100644 --- a/packages/fjl/src/list/concat.ts +++ b/packages/fjl/src/list/concat.ts @@ -1,6 +1,6 @@ import {append} from './append'; import {sliceCopy} from './utils/sliceCopy'; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/cycle.ts b/packages/fjl/src/list/cycle.ts index 40a9ea5f..535acdc5 100644 --- a/packages/fjl/src/list/cycle.ts +++ b/packages/fjl/src/list/cycle.ts @@ -1,7 +1,7 @@ import {curry} from "../function"; import {concat} from "./concat"; import {replicate} from "./replicate"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/difference.ts b/packages/fjl/src/list/difference.ts index 3657d6ce..08584bbe 100644 --- a/packages/fjl/src/list/difference.ts +++ b/packages/fjl/src/list/difference.ts @@ -2,7 +2,7 @@ import {curry, CurryOf2} from "../function/curry"; import {reduce} from "./utils"; import {sliceCopy} from "./utils/sliceCopy"; import {includes} from "../platform/slice"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export type Difference = CurryOf2 diff --git a/packages/fjl/src/list/dropWhile.ts b/packages/fjl/src/list/dropWhile.ts index 8e86b628..a9e571b1 100644 --- a/packages/fjl/src/list/dropWhile.ts +++ b/packages/fjl/src/list/dropWhile.ts @@ -4,7 +4,7 @@ import {findIndexWhere} from "./utils"; import {slice} from "../platform/slice"; import {PredForSlice} from "./types"; import {sliceFrom} from "./utils/sliceFrom"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; type DropWhile = CurryOf2, Slice, Slice>; diff --git a/packages/fjl/src/list/dropWhileEnd.ts b/packages/fjl/src/list/dropWhileEnd.ts index be720acb..7f671cdb 100644 --- a/packages/fjl/src/list/dropWhileEnd.ts +++ b/packages/fjl/src/list/dropWhileEnd.ts @@ -1,14 +1,14 @@ import {curry, CurryOf2} from "../function/curry"; import {findIndexWhereRight} from "./utils"; import {of} from "../object/of"; -import {Slice, SlicePred} from "../types/data"; +import {Slice, PredForSlice} from "../types"; import {$sliceTo} from "./utils/sliceTo"; -type DropWhileEnd = CurryOf2, Slice, Slice>; +type DropWhileEnd = CurryOf2, Slice, Slice>; export const - dropWhileEnd = (p: SlicePred, list: Slice): Slice => { + dropWhileEnd = (p: PredForSlice, list: Slice): Slice => { const splitPoint = findIndexWhereRight( (x, i, xs) => !p(x, i, xs), diff --git a/packages/fjl/src/list/elemIndices.ts b/packages/fjl/src/list/elemIndices.ts index 6271a5bf..5d89348a 100644 --- a/packages/fjl/src/list/elemIndices.ts +++ b/packages/fjl/src/list/elemIndices.ts @@ -1,6 +1,6 @@ import {curry, CurryOf2} from "../function"; import {findIndices} from "./findIndices"; -import {Slice, SlicePred} from "../types/data"; +import {Slice, PredForSlice} from "../types"; import {$equal} from "../boolean/equal"; type ElemIndices = CurryOf2, T | undefined> @@ -8,7 +8,7 @@ type ElemIndices = CurryOf2, T | undefined> export const elemIndices = (value: T, xs: Slice): T | any => - findIndices($equal(value) as SlicePred, xs), + findIndices($equal(value) as PredForSlice, xs), /** * Returns found "value" indices. diff --git a/packages/fjl/src/list/filter.ts b/packages/fjl/src/list/filter.ts index cdf66cee..f374e14f 100644 --- a/packages/fjl/src/list/filter.ts +++ b/packages/fjl/src/list/filter.ts @@ -1,15 +1,15 @@ import {curry, CurryOf2} from "../function/curry"; -import {Slice, SlicePred} from "../types/data"; +import {Slice, PredForSlice} from "../types"; import {typeOf} from "../object/typeOf"; -type Filter = CurryOf2, Slice, T[]>; +type Filter = CurryOf2, Slice, T[]>; export const /** * Filters a structure of elements using given predicate (`pred`) (same as `[].filter`). */ - filter = (pred: SlicePred, xs: Slice): Slice => { + filter = (pred: PredForSlice, xs: Slice): Slice => { let ind = 0; const limit = xs.length, isString = typeOf(xs) === 'String'; diff --git a/packages/fjl/src/list/foldl1.ts b/packages/fjl/src/list/foldl1.ts index 2ab3928b..dbd9e2cb 100644 --- a/packages/fjl/src/list/foldl1.ts +++ b/packages/fjl/src/list/foldl1.ts @@ -2,12 +2,12 @@ import {curry, CurryOf2} from "../function/curry"; import {uncons} from "./uncons"; import {reduce} from "./utils/reduce"; import {ReduceOp} from "../platform/types"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const /** - * A variant of `foldl` except that this one doesn't require the starting point. The starting point/value will be pulled + * A variant of `foldl` except that this one doesn't require the starting point value. The starting point/value will be pulled * out from a copy of the container. */ foldl1 = (op: ReduceOp, RetT>, xs: Slice): RetT => { diff --git a/packages/fjl/src/list/foldr1.ts b/packages/fjl/src/list/foldr1.ts index e990d73e..1f5baf79 100644 --- a/packages/fjl/src/list/foldr1.ts +++ b/packages/fjl/src/list/foldr1.ts @@ -2,7 +2,7 @@ import {curry, CurryOf2} from "../function/curry"; import {unconsr} from "./unconsr"; import {reduceRight} from "./utils/reduceRight"; import {ReduceOp} from "../platform"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/groupBy.ts b/packages/fjl/src/list/groupBy.ts index 18cc4e98..dbf6053a 100644 --- a/packages/fjl/src/list/groupBy.ts +++ b/packages/fjl/src/list/groupBy.ts @@ -1,7 +1,7 @@ import {curry, CurryOf2} from "../function/curry"; import {length} from "./length"; import {sliceCopy} from "./utils/sliceCopy"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; import {BinaryPred} from "../types"; export const diff --git a/packages/fjl/src/list/inits.ts b/packages/fjl/src/list/inits.ts index 27345c6e..7243bfa6 100644 --- a/packages/fjl/src/list/inits.ts +++ b/packages/fjl/src/list/inits.ts @@ -1,6 +1,6 @@ import {length} from "./length"; import {sliceTo} from "./utils/sliceTo"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; type Inits = (xs: Slice) => [Slice] | Slice; diff --git a/packages/fjl/src/list/insert.ts b/packages/fjl/src/list/insert.ts index 10d7e396..4c8b8be7 100644 --- a/packages/fjl/src/list/insert.ts +++ b/packages/fjl/src/list/insert.ts @@ -4,7 +4,7 @@ import {findIndex} from "./findIndex"; import {concat} from "./concat"; import {intersperse} from "./intersperse"; import {splitAt} from "./splitAt"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/insertBy.ts b/packages/fjl/src/list/insertBy.ts index 820d3307..0e7d2d13 100644 --- a/packages/fjl/src/list/insertBy.ts +++ b/packages/fjl/src/list/insertBy.ts @@ -5,7 +5,7 @@ import {concat} from "./concat"; import {push} from "./push"; import {sliceCopy} from "./utils/sliceCopy"; import {OrderingFunc} from "./utils"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; import {of} from "../object/of"; import {typeOf} from "../object/typeOf"; diff --git a/packages/fjl/src/list/intercalate.ts b/packages/fjl/src/list/intercalate.ts index 71fcd027..0cd7a28a 100644 --- a/packages/fjl/src/list/intercalate.ts +++ b/packages/fjl/src/list/intercalate.ts @@ -2,7 +2,7 @@ import {curry} from "../function"; import {isString} from "../object/is"; import {intersperse} from "./intersperse"; import {concat} from "./concat"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/intersperse.ts b/packages/fjl/src/list/intersperse.ts index 3172b029..88d55436 100644 --- a/packages/fjl/src/list/intersperse.ts +++ b/packages/fjl/src/list/intersperse.ts @@ -1,7 +1,7 @@ import {curry, CurryOf2} from "../function/curry"; import {of} from "../object/of"; import {isString} from "../object/is"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/isInfixOf.ts b/packages/fjl/src/list/isInfixOf.ts index a4e2bf74..7c975a06 100644 --- a/packages/fjl/src/list/isInfixOf.ts +++ b/packages/fjl/src/list/isInfixOf.ts @@ -1,6 +1,6 @@ import {curry2} from "../function/curry"; import {length} from "./length"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/map.ts b/packages/fjl/src/list/map.ts index ab244562..e5ab2c02 100644 --- a/packages/fjl/src/list/map.ts +++ b/packages/fjl/src/list/map.ts @@ -3,10 +3,10 @@ import {typeOf} from '../object/typeOf'; import {of} from '../object/of'; import {isFunctor} from '../object/is'; import {isset} from '../object/isset'; -import {Indexable, MapFunc, Functor} from "../types"; +import {Indexable, MapOp, Functor} from "../types"; export type MapType = - CurryOf2, Functor1, RetFunctor> + CurryOf2, Functor1, RetFunctor> /** * Maps a function onto a ListLike (string or array) or a functor (value containing a map method). @@ -14,7 +14,7 @@ export type MapType = export const map = ( - fn: MapFunc | Indexable, RetT>, + fn: MapOp | Indexable, RetT>, xs: Functor | Indexable): Functor | Indexable | any => { if (!isset(xs)) return of(xs); let out, diff --git a/packages/fjl/src/list/mapAccumL.ts b/packages/fjl/src/list/mapAccumL.ts index e74bf224..3d901aed 100644 --- a/packages/fjl/src/list/mapAccumL.ts +++ b/packages/fjl/src/list/mapAccumL.ts @@ -2,7 +2,7 @@ import {curry} from "../function/curry"; import {sliceCopy} from "./utils/sliceCopy"; import {length} from "./length"; import {Slice} from "../platform"; -import {Indexable, MapAccumFunc} from "../types"; +import {Indexable, MapAccumOp} from "../types"; export const @@ -10,7 +10,7 @@ export const * Performs a map then a reduce all in one (from left-to-right). Returns a tuple * containing the aggregated value and the result of mapping the passed in function on passed in list. */ - mapAccumL = (op: MapAccumFunc, zero: ZeroT, xs: Slice): [ZeroT, Slice] => { + mapAccumL = (op: MapAccumOp, zero: ZeroT, xs: Slice): [ZeroT, Slice] => { const list = sliceCopy(xs), limit = length(xs); if (!limit) { diff --git a/packages/fjl/src/list/mapAccumR.ts b/packages/fjl/src/list/mapAccumR.ts index 97e70826..c92277cd 100644 --- a/packages/fjl/src/list/mapAccumR.ts +++ b/packages/fjl/src/list/mapAccumR.ts @@ -1,7 +1,7 @@ import {curry} from "../function/curry"; import {sliceCopy} from "./utils/sliceCopy"; import {length} from "./length"; -import {Indexable, MapAccumFunc, Slice} from "../types"; +import {Indexable, MapAccumOp, Slice} from "../types"; export const @@ -9,7 +9,7 @@ export const * Performs a map and a reduce all in one (from right-to-left). Returns a tuple * containing the aggregated value and the result of mapping the passed in function on passed in list. */ - mapAccumR = (op: MapAccumFunc, zero: ZeroT, xs: Slice): [ZeroT, Slice] => { + mapAccumR = (op: MapAccumOp, zero: ZeroT, xs: Slice): [ZeroT, Slice] => { const list = sliceCopy(xs), limit = length(xs); if (!limit) { diff --git a/packages/fjl/src/list/partition.ts b/packages/fjl/src/list/partition.ts index 8c8828da..343e0788 100644 --- a/packages/fjl/src/list/partition.ts +++ b/packages/fjl/src/list/partition.ts @@ -1,6 +1,6 @@ import {curry, CurryOf2} from "../function"; import {PredForSlice} from "./types"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/permutations.ts b/packages/fjl/src/list/permutations.ts index f1660d0e..304b317f 100644 --- a/packages/fjl/src/list/permutations.ts +++ b/packages/fjl/src/list/permutations.ts @@ -2,7 +2,7 @@ import {length} from "./length"; import {swap} from "./utils"; import {sliceCopy} from "./utils/sliceCopy"; import {repeat} from "./repeat"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/span.ts b/packages/fjl/src/list/span.ts index 91615aea..5de1aea5 100644 --- a/packages/fjl/src/list/span.ts +++ b/packages/fjl/src/list/span.ts @@ -4,7 +4,7 @@ import {findIndexWhere} from "./utils"; import {of} from "../object/of"; import {splitAt} from "./splitAt"; import {sliceFrom} from "./utils/sliceFrom"; -import {Slice, SlicePred} from "../types"; +import {Slice, PredForSlice} from "../types"; export const @@ -13,7 +13,7 @@ export const * and items not matching predicate; E.g., Gives an * array of arrays; E.g., [[matching-items], [non-matching-items]] */ - span = (pred: SlicePred, list: Slice): [Slice, Slice] => { + span = (pred: PredForSlice, list: Slice): [Slice, Slice] => { const splitPoint = findIndexWhere(negateF3(pred), list) as number; return splitPoint === -1 ? [sliceFrom(0, list), of(list)] : diff --git a/packages/fjl/src/list/splitAt.ts b/packages/fjl/src/list/splitAt.ts index 9ce84051..83ed658f 100644 --- a/packages/fjl/src/list/splitAt.ts +++ b/packages/fjl/src/list/splitAt.ts @@ -1,6 +1,6 @@ import {sliceFrom} from "./utils/sliceFrom"; import {sliceTo} from "./utils/sliceTo"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; import {curry} from "../function"; export const diff --git a/packages/fjl/src/list/takeWhile.ts b/packages/fjl/src/list/takeWhile.ts index a7bc1608..f2a55dcc 100644 --- a/packages/fjl/src/list/takeWhile.ts +++ b/packages/fjl/src/list/takeWhile.ts @@ -4,15 +4,14 @@ import {reduceUntil} from "./utils"; import {isString} from "../object/is"; import {of} from "../object/of"; import {push} from "./push"; -import {Slice, SlicePred} from "../types/data"; -import {PredForSlice} from "./types"; +import {Slice, PredForSlice} from "../types"; export const /** * Gives an list with passed elements while predicate was true. */ - takeWhile = (pred: SlicePred, xs: Slice): Slice => + takeWhile = (pred: PredForSlice, xs: Slice): Slice => reduceUntil( negateF3(pred), // predicate isString(xs) ? (agg: Slice, x): string => diff --git a/packages/fjl/src/list/types.ts b/packages/fjl/src/list/types.ts index f83dca3d..903ec2e6 100644 --- a/packages/fjl/src/list/types.ts +++ b/packages/fjl/src/list/types.ts @@ -1,7 +1,5 @@ -import {PredicateOf3} from "../platform"; -import {Slice} from "../types/data"; -import {Indexable} from "../types"; +import {ArrayTernaryPred, Slice, Indexable} from "../types"; -export type PredForIndexable = PredicateOf3>; +export type PredForIndexable = ArrayTernaryPred>; -export type PredForSlice = PredicateOf3>; +export type PredForSlice = ArrayTernaryPred>; diff --git a/packages/fjl/src/list/utils/findIndexWhereRight.ts b/packages/fjl/src/list/utils/findIndexWhereRight.ts index a0a32443..9623a804 100644 --- a/packages/fjl/src/list/utils/findIndexWhereRight.ts +++ b/packages/fjl/src/list/utils/findIndexWhereRight.ts @@ -1,13 +1,13 @@ import {curry, CurryOf2} from "../../function/curry"; import {length} from "../length";; -import {Slice, SlicePred} from "../../types/data"; +import {Slice, PredForSlice} from "../../types"; export const /** * Returns found index or -1 if index not found. */ - findIndexWhereRight = (pred: SlicePred, arr: Slice): number => { + findIndexWhereRight = (pred: PredForSlice, arr: Slice): number => { let ind = length(arr) - 1; for (; ind >= 0; ind -= 1) { const predicateFulfilled = !!pred(arr[ind] as T, ind, arr); @@ -21,6 +21,6 @@ export const /** * Curried version of `findIndexWhereRight`. */ - $findIndexWhereRight = curry(findIndexWhereRight) as CurryOf2, Slice, number> + $findIndexWhereRight = curry(findIndexWhereRight) as CurryOf2, Slice, number> ; diff --git a/packages/fjl/src/list/utils/findIndicesWhere.ts b/packages/fjl/src/list/utils/findIndicesWhere.ts index b130e0ec..fad8ce6c 100644 --- a/packages/fjl/src/list/utils/findIndicesWhere.ts +++ b/packages/fjl/src/list/utils/findIndicesWhere.ts @@ -1,7 +1,6 @@ import {curry2, CurryOf2} from "../../function/curry"; -import {Slice, SlicePred} from "../../types/data"; +import {Slice, PredForSlice} from "../../types"; import {length} from "../length";; -import {PredForSlice} from "../types"; export const @@ -23,6 +22,6 @@ export const /** * Curried version of `findIndicesWhere`. */ - $findIndicesWhere = curry2(findIndicesWhere) as CurryOf2, Slice, number[] | undefined> + $findIndicesWhere = curry2(findIndicesWhere) as CurryOf2, Slice, number[] | undefined> ; diff --git a/packages/fjl/src/list/utils/findWhere.ts b/packages/fjl/src/list/utils/findWhere.ts index 7540d07f..dcaded23 100644 --- a/packages/fjl/src/list/utils/findWhere.ts +++ b/packages/fjl/src/list/utils/findWhere.ts @@ -1,13 +1,13 @@ import {curry, CurryOf2} from "../../function/curry"; import {length} from "../length"; -import {Slice, SlicePred} from "../../types/data"; +import {Slice, PredForSlice} from "../../types"; export const /** * Finds an item by predicate or returns `undefined`. */ - findWhere = (pred: SlicePred, xs: Slice): T | undefined => { + findWhere = (pred: PredForSlice, xs: Slice): T | undefined => { let ind = 0; const limit = length(xs); if (!limit) { @@ -25,6 +25,6 @@ export const /** * Curried version of `findWhere`. */ - $findWhere = curry(findWhere) as CurryOf2, Slice, any | undefined> + $findWhere = curry(findWhere) as CurryOf2, Slice, any | undefined> ; diff --git a/packages/fjl/src/list/utils/findexIndexWhere.ts b/packages/fjl/src/list/utils/findexIndexWhere.ts index 9ecfd0a6..958ea3f5 100644 --- a/packages/fjl/src/list/utils/findexIndexWhere.ts +++ b/packages/fjl/src/list/utils/findexIndexWhere.ts @@ -1,5 +1,5 @@ import {curry, CurryOf2} from "../../function/curry"; -import {Slice, SlicePred} from "../../types/data"; +import {Slice, PredForSlice} from "../../types"; import {length} from "../length";; export const @@ -7,7 +7,7 @@ export const /** * Finds index in slice (string|array) that matches given predicate or -1. */ - findIndexWhere = (pred: SlicePred, arr: Slice): number => { + findIndexWhere = (pred: PredForSlice, arr: Slice): number => { let ind = 0; const limit = length(arr); for (; ind < limit; ind += 1) { @@ -22,6 +22,6 @@ export const /** * Curried version of `findIndexWhere`. */ - $findIndexWhere = curry(findIndexWhere) as CurryOf2, Slice, number> + $findIndexWhere = curry(findIndexWhere) as CurryOf2, Slice, number> ; diff --git a/packages/fjl/src/list/utils/sliceCopy.ts b/packages/fjl/src/list/utils/sliceCopy.ts index 805e00c2..debe0b3e 100644 --- a/packages/fjl/src/list/utils/sliceCopy.ts +++ b/packages/fjl/src/list/utils/sliceCopy.ts @@ -1,4 +1,4 @@ -import {Slice} from "../../types/data"; +import {Slice} from "../../types"; import {sliceFrom} from "./sliceFrom"; export const diff --git a/packages/fjl/src/list/zip.ts b/packages/fjl/src/list/zip.ts index 6781daf3..cad78b23 100644 --- a/packages/fjl/src/list/zip.ts +++ b/packages/fjl/src/list/zip.ts @@ -2,7 +2,7 @@ import {curry} from "../function/curry"; import {length} from "./length"; import {reduce, toShortest} from "./utils"; import {push} from "./push"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; export const diff --git a/packages/fjl/src/list/zipWith.ts b/packages/fjl/src/list/zipWith.ts index b19c8762..d62a5793 100644 --- a/packages/fjl/src/list/zipWith.ts +++ b/packages/fjl/src/list/zipWith.ts @@ -2,7 +2,7 @@ import {curry} from "../function/curry"; import {length} from "./length"; import {reduce, toShortest} from "./utils"; import {push} from "./push"; -import {Slice} from "../types/data"; +import {Slice} from "../types"; import {Binary} from "../types"; export type TuplizeOp = Binary; diff --git a/packages/fjl/src/platform/README.md b/packages/fjl/src/platform/README.md index f26d2796..f0c29544 100644 --- a/packages/fjl/src/platform/README.md +++ b/packages/fjl/src/platform/README.md @@ -1,8 +1,7 @@ ## platform/ -Platform specific, functional version methods. +Platform specific, "functional version" methods. -This directory does not get exported in the project however modules from this directory get exported from other modules (in ../function, ../object modules, etc., for example). +*Note:* This directory doesn't get exported in the project, directly, however modules from this directory get exported via other exports (in '../function', '../object' modules, etc., for example). -### About testing here: -Modules here require minimal tests since the methods actually being -called are all "native" code. +### About testing: +Modules here require minimal tests since the methods here are actually "native" code. diff --git a/packages/fjl/src/platform/object/index.ts b/packages/fjl/src/platform/object/index.ts index d1dc9e2b..467072b7 100644 --- a/packages/fjl/src/platform/object/index.ts +++ b/packages/fjl/src/platform/object/index.ts @@ -4,7 +4,7 @@ import {curry, curry2, curry3, curry4, curry5, CurryOf2, CurryOf3, CurryOf4, CurryOf5} from "../../function/curry"; import {flip, flip3, flip4, flip5} from "../../function/flip"; -import {ObjectStatics} from "../../types/native"; +import {ObjectStatics} from "../../types"; export const diff --git a/packages/fjl/src/platform/slice/index.ts b/packages/fjl/src/platform/slice/index.ts index 4fcebf8a..96dd82a9 100644 --- a/packages/fjl/src/platform/slice/index.ts +++ b/packages/fjl/src/platform/slice/index.ts @@ -1,7 +1,7 @@ -import {Slice, SlicePred} from "../../types/data"; +import {Slice, PredForSlice} from "../../types"; import {curry2, curry3, CurryOf3} from "../../function"; -export {Slice, SlicePred}; +export {Slice, PredForSlice}; export const diff --git a/packages/fjl/src/types/README.md b/packages/fjl/src/types/README.md new file mode 100644 index 00000000..ccdbfa5c --- /dev/null +++ b/packages/fjl/src/types/README.md @@ -0,0 +1,7 @@ +## 'types/' + +### Array operator types +```typescript + + +``` diff --git a/packages/fjl/src/types/data.ts b/packages/fjl/src/types/data.ts index e05128f9..f44ed34b 100644 --- a/packages/fjl/src/types/data.ts +++ b/packages/fjl/src/types/data.ts @@ -1,16 +1,4 @@ import {Binary} from "./arity"; -import {ReduceOp} from "../platform"; - -export type MapFunc = (x?: T, i?: Ind, xs?: M) => RetT; - -export type MapAccumFunc> = - (agg?: ZeroT, x?: T, i?: Ind, xs?: Functor) => [ZeroT, ZeroT]; - -export interface Foldable extends Functor { - reduce(fn: ReduceOp, RetT>): RetT; - - reduceRight(fn: ReduceOp, RetT>): RetT; -} export interface Lengthable { readonly length?: number; @@ -43,8 +31,6 @@ export type Indexable = StringIndexable | NumberIndexable; export type Slice = T[] | string; -export type SlicePred = (x: T, i?: number | string, xs?: Slice) => boolean; - export type FunctorMapFn = ((a?: any, b?: any, c?: any, ...args: any[]) => RetT) | ((a?: any, b?: any, ...args: any[]) => RetT) | ((a?: any, ...args: any[]) => RetT); @@ -57,7 +43,7 @@ export interface FunctorConstructor { export interface Functor { valueOf(): T; - map(fn: FunctorMapFn): Functor | Functor; + map(fn: FunctorMapFn): Functor | Functor; readonly length?: number; } diff --git a/packages/fjl/src/types/index.ts b/packages/fjl/src/types/index.ts index ca245f1f..5373b60c 100644 --- a/packages/fjl/src/types/index.ts +++ b/packages/fjl/src/types/index.ts @@ -1,5 +1,6 @@ export * from './arity'; export * from './data'; +export * from './list'; export * from './native'; // @todo clean this up and allow only one of these types diff --git a/packages/fjl/src/types/list.ts b/packages/fjl/src/types/list.ts new file mode 100644 index 00000000..a8cf1938 --- /dev/null +++ b/packages/fjl/src/types/list.ts @@ -0,0 +1,22 @@ +import {Functor, Indexable, Slice} from "./data"; + +export type ArrayTernaryPred = (x: T, i?: Ind, xs?: FtrT) => boolean; + +export type ForEachOp = (x: T, i?: number | string, xs?: FtrT) => void | any; + +export type MapOp = (x: T, i?: Ind, xs?: FtrT) => RetT; + +export type ReduceOp = (agg: ZeroT, x: T, i?: number | string, xs?: FtrT) => ZeroT; + +export type MapAccumOp> = + (agg?: ZeroT, x?: T, i?: Ind, xs?: Functor) => [ZeroT, ZeroT]; + +export type PredForIndexable = ArrayTernaryPred>; + +export type PredForSlice = ArrayTernaryPred>; + +export interface Foldable extends Functor { + reduce(fn: ReduceOp, RetT>): RetT; + + reduceRight(fn: ReduceOp, RetT>): RetT; +} diff --git a/packages/fjl/tests/list/test-dropWhileEnd.ts b/packages/fjl/tests/list/test-dropWhileEnd.ts index 3c1c0397..d76ffaed 100644 --- a/packages/fjl/tests/list/test-dropWhileEnd.ts +++ b/packages/fjl/tests/list/test-dropWhileEnd.ts @@ -2,7 +2,7 @@ import {expectEqual, nonAlphaNumsArray, vowelsArray, vowelsString} from "../help import {dropWhileEnd} from "../../src/list/dropWhileEnd"; import {id} from "../../src/function/id"; import {UnaryPred} from "../../src/types"; -import {Slice} from "../../src/types/data"; +import {Slice} from "../../src/types"; // @todo move test-case message(s) into loop describe('#dropWhileEnd', () => { diff --git a/packages/fjl/tests/list/test-find.ts b/packages/fjl/tests/list/test-find.ts index bfef35c8..3f8784ba 100644 --- a/packages/fjl/tests/list/test-find.ts +++ b/packages/fjl/tests/list/test-find.ts @@ -1,6 +1,6 @@ import {expectEqual} from "../helpers"; import {find} from "../../src/list/find"; -import {Slice} from "../../src/types/data"; +import {Slice} from "../../src/types"; describe('#find', () => { const word = 'word'; diff --git a/packages/fjl/tests/list/test-mapAccumL.ts b/packages/fjl/tests/list/test-mapAccumL.ts index 7aa2c744..4d488b67 100644 --- a/packages/fjl/tests/list/test-mapAccumL.ts +++ b/packages/fjl/tests/list/test-mapAccumL.ts @@ -1,12 +1,12 @@ import {mapAccumL} from "../../src/list/mapAccumL"; import {Slice} from "../../src/platform"; -import {MapAccumFunc} from "../../src"; +import {MapAccumOp} from "../../src"; import {vowelsString} from "../helpers"; describe('#mapAccumL', () => { type ZeroT = number | string; - (<[string, MapAccumFunc, Slice, ZeroT, [ZeroT, Slice]][]>[ + (<[string, MapAccumOp, Slice, ZeroT, [ZeroT, Slice]][]>[ ['mapAccumL(multBy2Sums, number, number[]) === [number, number[]]', (agg: number, item: number) => { const product = item * 2; diff --git a/packages/fjl/tests/list/test-mapAccumR.ts b/packages/fjl/tests/list/test-mapAccumR.ts index c9b5a5c3..dbd3b03d 100644 --- a/packages/fjl/tests/list/test-mapAccumR.ts +++ b/packages/fjl/tests/list/test-mapAccumR.ts @@ -1,11 +1,11 @@ import {mapAccumR} from "../../src/list/mapAccumR"; import {expectEqual, vowelsString} from "../helpers"; -import {MapAccumFunc, mapAccumL, Slice} from "../../src"; +import {MapAccumOp, mapAccumL, Slice} from "../../src"; describe('#mapAccumR', () => { type ZeroT = number | string; - (<[string, MapAccumFunc, Slice, ZeroT, [ZeroT, Slice]][]>[ + (<[string, MapAccumOp, Slice, ZeroT, [ZeroT, Slice]][]>[ ['mapAccumR(multBy2Sums, number, number[]) === [number, number[]]', (agg: number, item: number) => { const product = item * 2; diff --git a/packages/fjl/tests/string/index_test.ts b/packages/fjl/tests/string/index_test.ts index 785be93b..3b1a82dd 100644 --- a/packages/fjl/tests/string/index_test.ts +++ b/packages/fjl/tests/string/index_test.ts @@ -19,7 +19,7 @@ import { unwords, words } from "../../src/string"; -import {Slice} from '../../src/types/data'; +import {Slice} from '../../src/types'; describe('#lines', () => { it('should split a string on all new line characters.', () => { diff --git a/tsconfig.json b/tsconfig.json index d08ad956..63eb8af8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,5 +17,5 @@ "exclude": [ "**/node_modules", "**/dist" - ] + ], } From e7c5a8d069ff3fbb78b4b5086861dc9361accc11 Mon Sep 17 00:00:00 2001 From: elycruz <603428+elycruz@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:38:57 -0400 Subject: [PATCH 2/2] #23 - Consolidated array typings into 'fjl/src/types'. --- packages/fjl/src/list/all.ts | 3 +-- packages/fjl/src/list/any.ts | 3 +-- packages/fjl/src/list/breakOnList.ts | 3 +-- packages/fjl/src/list/concatMap.ts | 7 +++---- packages/fjl/src/list/dropWhile.ts | 3 +-- packages/fjl/src/list/foldl1.ts | 3 +-- packages/fjl/src/list/foldr1.ts | 3 +-- packages/fjl/src/list/forEach.ts | 3 +-- packages/fjl/src/list/index.ts | 1 - packages/fjl/src/list/partition.ts | 3 +-- packages/fjl/src/list/types.ts | 5 ----- packages/fjl/src/list/utils/reduce.ts | 3 +-- packages/fjl/src/list/utils/reduceRight.ts | 3 +-- packages/fjl/src/list/utils/reduceUntil.ts | 6 ++---- packages/fjl/src/list/utils/reduceUntilRight.ts | 6 ++---- packages/fjl/src/platform/index.ts | 1 - packages/fjl/src/platform/types.ts | 7 ------- packages/fjl/tests/list-utils/test-findIndexWhere.ts | 3 +-- packages/fjl/tests/list-utils/test-findIndexWhereRight.ts | 3 +-- packages/fjl/tests/list-utils/test-findIndicesWhere.ts | 3 +-- packages/fjl/tests/list-utils/test-findWhere.ts | 3 +-- packages/fjl/tests/list/test-findIndex.ts | 3 +-- packages/fjl/tests/list/test-findIndices.ts | 3 +-- packages/fjl/tests/list/test-partition.ts | 3 +-- packages/fjl/tests/list/test-span.ts | 4 ++-- packages/fjl/tests/list/test-takeWhile.ts | 6 +++--- 26 files changed, 29 insertions(+), 65 deletions(-) delete mode 100644 packages/fjl/src/list/types.ts delete mode 100644 packages/fjl/src/platform/types.ts diff --git a/packages/fjl/src/list/all.ts b/packages/fjl/src/list/all.ts index fff6ddcf..83f82466 100644 --- a/packages/fjl/src/list/all.ts +++ b/packages/fjl/src/list/all.ts @@ -1,7 +1,6 @@ import {curry, CurryOf2} from "../function"; import {length} from "./length"; -import {Indexable} from "../types"; -import {PredForIndexable} from "./types"; +import {PredForIndexable, Indexable} from "../types"; import {keys} from "../platform/object"; export type All = CurryOf2 diff --git a/packages/fjl/src/list/any.ts b/packages/fjl/src/list/any.ts index e504bfef..3ac716fa 100644 --- a/packages/fjl/src/list/any.ts +++ b/packages/fjl/src/list/any.ts @@ -1,7 +1,6 @@ import {curry, CurryOf2} from "../function/curry"; import {length} from "./length"; -import {PredForIndexable} from "./types"; -import {Indexable} from "../types"; +import {PredForIndexable, Indexable} from "../types"; import {keys} from "../platform/object"; export type Any = CurryOf2; diff --git a/packages/fjl/src/list/breakOnList.ts b/packages/fjl/src/list/breakOnList.ts index 10797d4e..363a91ce 100644 --- a/packages/fjl/src/list/breakOnList.ts +++ b/packages/fjl/src/list/breakOnList.ts @@ -4,9 +4,8 @@ import {findIndexWhere} from "./utils/findexIndexWhere"; import {of} from "../object/of"; import {reverse} from "./reverse"; import {splitAt} from "./splitAt"; -import {Slice} from "../types"; +import {Slice, PredForSlice} from "../types"; import {sliceFrom} from "./utils/sliceFrom"; -import {PredForSlice} from "./types"; export type BreakOnList = CurryOf2; diff --git a/packages/fjl/src/list/concatMap.ts b/packages/fjl/src/list/concatMap.ts index d72bd7a5..6182fe88 100644 --- a/packages/fjl/src/list/concatMap.ts +++ b/packages/fjl/src/list/concatMap.ts @@ -1,8 +1,7 @@ import {curry, CurryOf2} from "../function"; import {concat} from "./concat"; import {map} from "./map"; -import {MapOp} from "../platform"; -import {Indexable} from "../types"; +import {MapOp, Indexable} from "../types"; export type ConcatMap = CurryOf2 @@ -13,11 +12,11 @@ export const * Map a function over all the elements of a container and concatenate the resulting lists. */ concatMap = ( - fn: MapOp, RetT>, + fn: MapOp, RetT>, indexable: Indexable ): Indexable => concat(map(fn, indexable)), - $concatMap = curry(concatMap) as ConcatMap, Indexable, any> + $concatMap = curry(concatMap) as ConcatMap, Indexable, any> ; diff --git a/packages/fjl/src/list/dropWhile.ts b/packages/fjl/src/list/dropWhile.ts index a9e571b1..a5f3f117 100644 --- a/packages/fjl/src/list/dropWhile.ts +++ b/packages/fjl/src/list/dropWhile.ts @@ -2,9 +2,8 @@ import {curry, CurryOf2} from "../function/curry"; import {length} from "./length"; import {findIndexWhere} from "./utils"; import {slice} from "../platform/slice"; -import {PredForSlice} from "./types"; import {sliceFrom} from "./utils/sliceFrom"; -import {Slice} from "../types"; +import {PredForSlice, Slice} from "../types"; type DropWhile = CurryOf2, Slice, Slice>; diff --git a/packages/fjl/src/list/foldl1.ts b/packages/fjl/src/list/foldl1.ts index dbd9e2cb..5ffe0542 100644 --- a/packages/fjl/src/list/foldl1.ts +++ b/packages/fjl/src/list/foldl1.ts @@ -1,8 +1,7 @@ import {curry, CurryOf2} from "../function/curry"; import {uncons} from "./uncons"; import {reduce} from "./utils/reduce"; -import {ReduceOp} from "../platform/types"; -import {Slice} from "../types"; +import {ReduceOp, Slice} from "../types"; export const diff --git a/packages/fjl/src/list/foldr1.ts b/packages/fjl/src/list/foldr1.ts index 1f5baf79..63c57193 100644 --- a/packages/fjl/src/list/foldr1.ts +++ b/packages/fjl/src/list/foldr1.ts @@ -1,8 +1,7 @@ import {curry, CurryOf2} from "../function/curry"; import {unconsr} from "./unconsr"; import {reduceRight} from "./utils/reduceRight"; -import {ReduceOp} from "../platform"; -import {Slice} from "../types"; +import {Slice, ReduceOp} from "../types"; export const diff --git a/packages/fjl/src/list/forEach.ts b/packages/fjl/src/list/forEach.ts index 2cb3425a..a289e3a5 100644 --- a/packages/fjl/src/list/forEach.ts +++ b/packages/fjl/src/list/forEach.ts @@ -1,7 +1,6 @@ import {curry} from "../function/curry"; import {length} from "./length"; -import {ForEachOp} from "../platform"; -import {Slice} from "../types"; +import {ForEachOp, Slice} from "../types"; export const diff --git a/packages/fjl/src/list/index.ts b/packages/fjl/src/list/index.ts index 12028c27..3a9bdc66 100644 --- a/packages/fjl/src/list/index.ts +++ b/packages/fjl/src/list/index.ts @@ -88,7 +88,6 @@ export * from './tails'; export * from './take'; export * from './takeWhile'; export * from './transpose'; -export * from './types'; export * from './uncons'; export * from './unconsr'; export * from './unfoldr'; diff --git a/packages/fjl/src/list/partition.ts b/packages/fjl/src/list/partition.ts index 343e0788..370b122d 100644 --- a/packages/fjl/src/list/partition.ts +++ b/packages/fjl/src/list/partition.ts @@ -1,6 +1,5 @@ import {curry, CurryOf2} from "../function"; -import {PredForSlice} from "./types"; -import {Slice} from "../types"; +import {PredForSlice, Slice} from "../types"; export const diff --git a/packages/fjl/src/list/types.ts b/packages/fjl/src/list/types.ts deleted file mode 100644 index 903ec2e6..00000000 --- a/packages/fjl/src/list/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -import {ArrayTernaryPred, Slice, Indexable} from "../types"; - -export type PredForIndexable = ArrayTernaryPred>; - -export type PredForSlice = ArrayTernaryPred>; diff --git a/packages/fjl/src/list/utils/reduce.ts b/packages/fjl/src/list/utils/reduce.ts index 50f2bc73..57b93505 100644 --- a/packages/fjl/src/list/utils/reduce.ts +++ b/packages/fjl/src/list/utils/reduce.ts @@ -1,7 +1,6 @@ import {$reduceUntil, reduceUntil} from "./reduceUntil"; import {alwaysFalse} from "../../boolean/alwaysFalse"; -import {ReduceOp} from "../../platform"; -import {Indexable} from "../../types"; +import {ReduceOp, Indexable} from "../../types"; export const diff --git a/packages/fjl/src/list/utils/reduceRight.ts b/packages/fjl/src/list/utils/reduceRight.ts index 36e46b4d..7e34ff0e 100644 --- a/packages/fjl/src/list/utils/reduceRight.ts +++ b/packages/fjl/src/list/utils/reduceRight.ts @@ -1,7 +1,6 @@ import {$reduceUntilRight, reduceUntilRight} from "./reduceUntilRight"; import {alwaysFalse} from "../../boolean/alwaysFalse"; -import {ReduceOp} from "../../platform"; -import {Indexable} from "../../types"; +import {ReduceOp, Indexable} from "../../types"; export const diff --git a/packages/fjl/src/list/utils/reduceUntil.ts b/packages/fjl/src/list/utils/reduceUntil.ts index 1a48559a..b86e4854 100644 --- a/packages/fjl/src/list/utils/reduceUntil.ts +++ b/packages/fjl/src/list/utils/reduceUntil.ts @@ -1,8 +1,6 @@ import {curry, CurryOf4} from "../../function/curry"; -import {PredForIndexable, PredForSlice} from "../types"; -import {ReduceOp} from "../../platform/types"; -import {length} from "../length";; -import {Indexable, Lengthable} from "../../types"; +import {ReduceOp, PredForIndexable, Indexable, Lengthable} from "../../types"; +import {length} from "../length"; export type ReduceUntil = CurryOf4, ReduceOp, RetT>, // @todo Refactor `ReduceOp` diff --git a/packages/fjl/src/list/utils/reduceUntilRight.ts b/packages/fjl/src/list/utils/reduceUntilRight.ts index ccdb43ef..e36c6a5f 100644 --- a/packages/fjl/src/list/utils/reduceUntilRight.ts +++ b/packages/fjl/src/list/utils/reduceUntilRight.ts @@ -1,8 +1,6 @@ import {curry} from "../../function/curry"; -import {length} from "../length";; -import {Indexable} from "../../types"; -import {PredForIndexable} from "../types"; -import {ReduceOp} from "../../platform"; +import {length} from "../length"; +import {Indexable, ReduceOp, PredForIndexable} from "../../types"; export const diff --git a/packages/fjl/src/platform/index.ts b/packages/fjl/src/platform/index.ts index bb73d78c..9889ea47 100644 --- a/packages/fjl/src/platform/index.ts +++ b/packages/fjl/src/platform/index.ts @@ -5,4 +5,3 @@ export * from './function'; export * from './object'; export * from './slice'; export * from './string'; -export * from './types'; diff --git a/packages/fjl/src/platform/types.ts b/packages/fjl/src/platform/types.ts deleted file mode 100644 index 37ca5fbf..00000000 --- a/packages/fjl/src/platform/types.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type PredicateOf3 = (x: Tx, i?: Ti, xs?: Txs) => boolean; - -export type ForEachOp = (x: T, i?: number | string, xs?: FtrT) => void | any; - -export type MapOp = (x: T, i?: number | string, xs?: FtrT) => RetT; - -export type ReduceOp = (agg: ZeroT, x: T, i?: number | string, xs?: FtrT) => ZeroT; diff --git a/packages/fjl/tests/list-utils/test-findIndexWhere.ts b/packages/fjl/tests/list-utils/test-findIndexWhere.ts index 60613a4c..95d9a501 100644 --- a/packages/fjl/tests/list-utils/test-findIndexWhere.ts +++ b/packages/fjl/tests/list-utils/test-findIndexWhere.ts @@ -1,6 +1,5 @@ import {findIndexWhere} from "../../src/list/utils/findexIndexWhere"; -import {PredForSlice} from "../../src/list/types"; -import {Slice} from "../../src/platform/slice"; +import {Slice, PredForSlice} from "../../src/types"; import {alphabetArray, vowelsArray, vowelsString} from "../helpers"; describe(`#findIndexWhere`, () => { diff --git a/packages/fjl/tests/list-utils/test-findIndexWhereRight.ts b/packages/fjl/tests/list-utils/test-findIndexWhereRight.ts index a3542cab..db74e612 100644 --- a/packages/fjl/tests/list-utils/test-findIndexWhereRight.ts +++ b/packages/fjl/tests/list-utils/test-findIndexWhereRight.ts @@ -1,6 +1,5 @@ import {findIndexWhereRight} from "../../src/list/utils"; -import {PredForSlice} from "../../src/list/types"; -import {Slice} from "../../src/platform/slice"; +import {Slice, PredForSlice} from "../../src/types"; import { alphabetArray, vowelsArray, diff --git a/packages/fjl/tests/list-utils/test-findIndicesWhere.ts b/packages/fjl/tests/list-utils/test-findIndicesWhere.ts index a3bd56f2..9be71ce7 100644 --- a/packages/fjl/tests/list-utils/test-findIndicesWhere.ts +++ b/packages/fjl/tests/list-utils/test-findIndicesWhere.ts @@ -1,6 +1,5 @@ import {findIndicesWhere} from "../../src/list/utils/findIndicesWhere"; -import {PredForSlice} from "../../src/list/types"; -import {Slice} from "../../src/platform/slice"; +import {Slice, PredForSlice} from "../../src/types"; import {alphabetCharCodeRange, alphabetString, expectEqual, expectError, vowelIndices, vowelsArray} from "../helpers"; describe(`#listUtils.findIndicesWhere`, () => { diff --git a/packages/fjl/tests/list-utils/test-findWhere.ts b/packages/fjl/tests/list-utils/test-findWhere.ts index 14789adc..9af0db4e 100644 --- a/packages/fjl/tests/list-utils/test-findWhere.ts +++ b/packages/fjl/tests/list-utils/test-findWhere.ts @@ -1,6 +1,5 @@ import {findWhere} from "../../src/list/utils/findWhere"; -import {PredForSlice} from "../../src/list/types"; -import {Slice} from "../../src/platform/slice"; +import {Slice, PredForSlice} from "../../src/types"; import {alphabetArray, alphabetString, expectEqual, expectError, vowelsArray, vowelsString} from "../helpers"; describe(`#findWhere`, () => { diff --git a/packages/fjl/tests/list/test-findIndex.ts b/packages/fjl/tests/list/test-findIndex.ts index 86fcef76..5195ef1b 100644 --- a/packages/fjl/tests/list/test-findIndex.ts +++ b/packages/fjl/tests/list/test-findIndex.ts @@ -1,5 +1,4 @@ -import {Slice} from "../../src/platform"; -import {PredForSlice} from "../../src/list/types"; +import {Slice, PredForSlice} from "../../src/types"; import {isVowel, notIsVowel} from "../helpers"; import {alphabetArray, alphabetString, vowelsArray, vowelsString} from "../helpers"; import {findIndex} from "../../src"; diff --git a/packages/fjl/tests/list/test-findIndices.ts b/packages/fjl/tests/list/test-findIndices.ts index ff3cc235..35725932 100644 --- a/packages/fjl/tests/list/test-findIndices.ts +++ b/packages/fjl/tests/list/test-findIndices.ts @@ -1,6 +1,5 @@ import {findIndices} from "../../src/list/findIndices"; -import {PredForSlice} from "../../src/list/types"; -import {Slice} from "../../src/platform/slice"; +import {Slice, PredForSlice} from "../../src/types"; import {alphabetCharCodeRange} from "../helpers"; describe(`#listUtils.findIndices`, () => { diff --git a/packages/fjl/tests/list/test-partition.ts b/packages/fjl/tests/list/test-partition.ts index 08561f0a..72123a5c 100644 --- a/packages/fjl/tests/list/test-partition.ts +++ b/packages/fjl/tests/list/test-partition.ts @@ -1,7 +1,6 @@ import {partition} from "../../src/list"; import {alphabetArray, alphabetString, isVowel, vowelsArray} from "../helpers"; -import {Slice} from "../../src/platform/slice"; -import {PredForSlice} from "../../src/list/types"; +import {Slice, PredForSlice} from "../../src/types"; describe('#partition', () => { const nonVowels = alphabetArray.filter(x => !isVowel(x)); diff --git a/packages/fjl/tests/list/test-span.ts b/packages/fjl/tests/list/test-span.ts index 19e3d469..a6237a3b 100644 --- a/packages/fjl/tests/list/test-span.ts +++ b/packages/fjl/tests/list/test-span.ts @@ -1,6 +1,6 @@ import {alphabetArray, alphabetString, expectEqual, isVowel, nonAlphaNums, nonAlphaNumsArray} from "../helpers"; -import {PredForIndexable, span} from "../../src/list"; -import {Slice} from "../../src"; +import {span} from "../../src/list"; +import {PredForIndexable, Slice} from "../../src/types"; describe('#span', () => { it('should give the span of elements matching predicate and elements not matching predicate.', () => { diff --git a/packages/fjl/tests/list/test-takeWhile.ts b/packages/fjl/tests/list/test-takeWhile.ts index 604cd595..73f8a7a5 100644 --- a/packages/fjl/tests/list/test-takeWhile.ts +++ b/packages/fjl/tests/list/test-takeWhile.ts @@ -1,6 +1,6 @@ import { alphabetArray, - alphabetString, expectEqual, + alphabetString, isVowel, nonAlphaNums, nonAlphaNumsArray, @@ -8,8 +8,8 @@ import { vowelsString } from "../helpers"; import {range} from "../../src/list/range"; -import {forEach, PredForIndexable, takeWhile} from "../../src/list"; -import {Slice} from "../../src/platform/slice"; +import {takeWhile} from "../../src/list"; +import {Slice, PredForIndexable} from "../../src/types"; describe('#takeWhile', () => { it('should take elements while predicate is fulfilled and vice-versa', () => {