-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: issue-#103 - fjl-validator cleanup
- Cleaned types in: - 'dropWhileEnd' - Made method stricter, and more flexible (!?!?) at the same time. - 'forEach' - Made type clearer, and more flexible. - 'map' - Made type clearer. - 'tails', and 'subsequence' - Updated these to use 'Slice' type. - Removed deprecation tag from: - 'ArrayTypeConstructor', and, - 'TypedArray' - Cleaned up some doc blocks. - Cleaned up some doc blocks. - Deprecated 'types/data/list' type method types. - Consolidated some code in rollup.config. - Updated rollup.config to output cjs/mjs files with cjs/mjs extensions, respectively. - Performed (small) type cleanups in fjl-inputFilter, and fjl-validator string length validator. - package.json - Removed 'exports' field - Currently very difficult to support for our use case so the feature is tabled until we could solve the 'exporting type files for cjs, and mjs' issue.
- Loading branch information
Showing
20 changed files
with
101 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"files": [ | ||
"./src/index.ts" | ||
], | ||
"exclude": [ | ||
"dist/", | ||
"node_modules/", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
"name": "fjl", | ||
"version": "2.0.0-alpha.5", | ||
"description": "Functional Javascript Library.", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"main": "./dist/cjs/index.cjs", | ||
"module": "./dist/esm/index.mjs", | ||
"typings": "./dist/esm/index.d.ts", | ||
"files": [ | ||
"./dist", | ||
|
@@ -23,16 +23,6 @@ | |
"prelude", | ||
"combinators" | ||
], | ||
"exports": { | ||
".": { | ||
"require": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js" | ||
}, | ||
"./*": { | ||
"require": "./dist/cjs/*.js", | ||
"module": "./dist/esm/*.js" | ||
} | ||
}, | ||
"author": "Ely De La Cruz <[email protected]>", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import {ForEachOp} from "../types"; | ||
import {Ternary} from "../types"; | ||
|
||
export const | ||
|
||
/** | ||
* "For each" function - same as `[].forEach` except for iterables (strings, `Map`s, ...) in general. | ||
*/ | ||
forEach = <T>(fn: ForEachOp, iter: Iterable<T>): void => { | ||
forEach = <T, TS extends Iterable<T>>(fn: Ternary<T, number, TS>, iter: TS): void => { | ||
if (!iter) return; | ||
let ind = 0; | ||
for (const x of iter) { | ||
fn(x, ind++, iter); | ||
} | ||
}, | ||
|
||
$forEach = <T>(fn: ForEachOp) => | ||
(iter: Iterable<T>): void => forEach(fn, iter) | ||
$forEach = <T, TS extends Iterable<T>>(fn: Ternary<T, number, TS>) => | ||
(iter: TS): void => forEach(fn, iter) | ||
|
||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import {Constructable, MapOp} from "../types"; | ||
import {ArrayTypeConstructor, Ternary} from "../types"; | ||
|
||
export const | ||
|
||
/** | ||
* Maps a function onto a ListLike (string or array) or a functor (value containing a map method). | ||
* Maps a function over an "array type" container of values. | ||
*/ | ||
map = <T = any>( | ||
fn: MapOp, | ||
fn: Ternary<T, number, T[]>, | ||
xs: T[] | ||
): ReturnType<typeof fn>[] => { | ||
const limit = xs.length, | ||
out = new (xs.constructor as Constructable)(limit); | ||
out = new (xs.constructor as ArrayTypeConstructor)(limit); | ||
for (let i = 0; i < limit; i += 1) { | ||
out[i] = fn(xs[i], i, xs); | ||
} | ||
return out; | ||
return out as ReturnType<typeof fn>[]; | ||
}, | ||
|
||
/** | ||
* Curried version of `map` method. | ||
*/ | ||
$map = <T = any> | ||
(fn: MapOp) => | ||
(fn: Ternary<T, number, T[]>) => | ||
(xs: T[]): ReturnType<typeof fn>[] => | ||
map(fn, xs) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
import {NumberIndexable, Slice} from "./data"; | ||
import {TernaryPred} from "./arity"; | ||
|
||
// @todo Normalize these types - They should accept same type params instead of mixed length params. | ||
|
||
export type ForEachOp<T = any, FtrT = any> = (x: T, i?: number | keyof FtrT, xs?: FtrT) => void | any; | ||
/** | ||
* @deprecated Use `Ternary` type instead. | ||
* | ||
* Foreach operation function type. | ||
*/ | ||
export type ForEachOp<T, IterT extends Iterable<T>> = (x: T, i?: number | keyof IterT, xs?: IterT) => void | any; | ||
|
||
export type MapOp<T = any, FtrT = any> = (x: T, i?: number | keyof FtrT, xs?: FtrT) => FtrT; | ||
/** | ||
* @deprecated Use `Ternary` instead. | ||
* | ||
* Map operation function type. | ||
*/ | ||
export type MapOp<T = any, FtrT = any, FtrT2 extends FtrT = any> = (x: T, i?: number | keyof FtrT, xs?: FtrT) => FtrT2; | ||
|
||
export type ReduceOp<T = any, FnctrT = any, ZeroT = any> = (agg: ZeroT, x?: T, i?: number | keyof FnctrT, xs?: FnctrT) => ZeroT; | ||
/** | ||
* @deprecated Use `Quaternary` instead. | ||
* | ||
* Reduce operation function type. | ||
*/ | ||
export type ReduceOp<T = any, FtrT = any, ZeroT = any> = (agg: ZeroT, x?: T, i?: number | keyof FtrT, xs?: FtrT) => ZeroT; | ||
|
||
/** | ||
* @deprecated Use `Quinary` instead. | ||
* | ||
* "Map + Accumulate", A.K.A. Map-Reduce, function type. | ||
*/ | ||
export type MapAccumOp<A = any, B = any, C = any, Ind = number | string, Functor = Slice<B>> = | ||
(agg?: A, b?: B, i?: Ind, bs?: Functor) => [A, C]; | ||
|
||
/** | ||
* @deprecated Use `TernaryPred` instead. | ||
* | ||
* Predicate for Slice operation func type. | ||
* @todo Should this be `PredForNumIndexable`, instead? | ||
*/ | ||
export type PredForSlice<T = any, TS extends NumberIndexable<T> = NumberIndexable<T>> = TernaryPred<T, number, TS>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.