@ebflat9/fp
Advanced tools
Comparing version 1.2.55 to 1.2.56
{ | ||
"root": true, | ||
"env": { | ||
"es2021": true, | ||
"shared-node-browser": true, | ||
"node": true, | ||
"browser": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
"root": true, | ||
"env": { | ||
"es2021": true, | ||
"shared-node-browser": true, | ||
"node": true, | ||
"browser": true, | ||
"mocha": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:prettier/recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"no-promise-executor-return": "warn", | ||
"require-atomic-updates": "error", | ||
"accessor-pairs": "warn", | ||
"array-callback-return": "error", | ||
"complexity": "error", | ||
"consistent-return": "warn", | ||
"curly": [ | ||
"error", | ||
"multi-line" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
"dot-notation": "warn", | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"no-promise-executor-return": "warn", | ||
"require-atomic-updates": "error", | ||
"accessor-pairs": "warn", | ||
"array-callback-return": "error", | ||
"complexity": "error", | ||
"consistent-return": "warn", | ||
"curly": [ | ||
"error", | ||
"multi-line" | ||
], | ||
"dot-notation": "warn", | ||
"eqeqeq": [ | ||
"error", | ||
"smart" | ||
], | ||
"grouped-accessor-pairs": [ | ||
"error", | ||
"getBeforeSet" | ||
], | ||
"no-unused-vars": "warn", | ||
"no-param-reassign": "error", | ||
"prefer-promise-reject-errors": "error", | ||
"no-var": "error", | ||
"prefer-const": [ | ||
"warn", | ||
{ | ||
"destructuring": "any" | ||
} | ||
], | ||
"no-unneeded-ternary": "error", | ||
"no-duplicate-imports": [ | ||
"error", | ||
{ | ||
"includeExports": true | ||
} | ||
], | ||
"no-constant-condition": [ | ||
"error", | ||
{ | ||
"checkLoops": false | ||
} | ||
], | ||
"func-names": [ | ||
"warn", | ||
"always" | ||
], | ||
"object-shorthand": "warn" | ||
} | ||
"grouped-accessor-pairs": [ | ||
"error", | ||
"getBeforeSet" | ||
], | ||
"no-unused-vars": "warn", | ||
"no-param-reassign": "error", | ||
"prefer-promise-reject-errors": "error", | ||
"no-var": "error", | ||
"prefer-const": [ | ||
"warn", | ||
{ | ||
"destructuring": "any" | ||
} | ||
], | ||
"no-unneeded-ternary": "error", | ||
"no-duplicate-imports": [ | ||
"error", | ||
{ | ||
"includeExports": true | ||
} | ||
], | ||
"no-constant-condition": [ | ||
"error", | ||
{ | ||
"checkLoops": false | ||
} | ||
], | ||
"func-names": [ | ||
"warn", | ||
"always" | ||
], | ||
"object-shorthand": "warn" | ||
} | ||
} |
{ | ||
"name": "@ebflat9/fp", | ||
"version": "1.2.55", | ||
"version": "1.2.56", | ||
"description": "my fp utils", | ||
@@ -32,10 +32,14 @@ "source": "src/index.ts", | ||
"devDependencies": { | ||
"@types/node": "^16.11.7", | ||
"@parcel/core": "^2.0.1", | ||
"@parcel/packager-ts": "^2.0.1", | ||
"@parcel/transformer-typescript-types": "^2.0.1", | ||
"@types/node": "^16.11.7", | ||
"@typescript-eslint/eslint-plugin": "^5.3.1", | ||
"@typescript-eslint/parser": "^5.3.1", | ||
"eslint": "^8.2.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mocha": "^9.1.3", | ||
"parcel": "^2.0.1", | ||
"prettier": "^2.5.1", | ||
"typescript": "^4.4.4" | ||
@@ -42,0 +46,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint no-unused-vars: 0 */ | ||
@@ -80,3 +81,3 @@ import { identity } from '../functions/utils' | ||
? Ma.merge().call(Ma, this.value) | ||
: this.value(Ma.merge()) | ||
: this.value(Ma.merge()), | ||
) | ||
@@ -83,0 +84,0 @@ : Maybe.of(Ma.merge().call(Ma, this.value)) |
/* eslint no-unused-vars: 0 */ | ||
export class Pair { | ||
@@ -102,3 +101,3 @@ #left | ||
constructor(types: string[]) { | ||
types.forEach(type => this.#types.add(type)) | ||
types.forEach((type) => this.#types.add(type)) | ||
} | ||
@@ -105,0 +104,0 @@ has(type: string) { |
@@ -0,3 +1,3 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint no-unused-vars: 0 */ | ||
import { isFunction } from '../functions/predicates' | ||
@@ -29,3 +29,5 @@ import { errorWith } from './utils' | ||
static fromPromise<X>(p: Promise<X>) { | ||
return p.then(result => new Success(result)).catch(err => new Failure(err.message)) | ||
return p | ||
.then((result) => new Success(result)) | ||
.catch((err) => new Failure(err.message)) | ||
} | ||
@@ -103,3 +105,3 @@ [Symbol.toPrimitive](hint: string) { | ||
? Rs.merge().call(Rs, this.value) | ||
: this.value(Rs.merge()) | ||
: this.value(Rs.merge()), | ||
) | ||
@@ -106,0 +108,0 @@ : Result.of(Rs.merge().call(Rs, this.value)) |
@@ -11,3 +11,3 @@ /* eslint no-unused-vars: 0 */ | ||
export const after = (...fns: IGenericFunction[]): IDecorator => | ||
function after(target: any, name: string, descriptor: PropertyDescriptor) { | ||
function after(_target: any, _name: string, descriptor: PropertyDescriptor) { | ||
const method = descriptor.value | ||
@@ -26,3 +26,3 @@ | ||
export const before = (...fns: IGenericFunction[]): IDecorator => | ||
function before(target: any, name: string, descriptor: PropertyDescriptor) { | ||
function before(_target: any, _name: string, descriptor: PropertyDescriptor) { | ||
const method = descriptor.value | ||
@@ -40,3 +40,7 @@ | ||
export const provided = (...fns: IGenericFunction[]): IDecorator => | ||
function provided(target: any, name: string, descriptor: PropertyDescriptor) { | ||
function provided( | ||
_target: any, | ||
_name: string, | ||
descriptor: PropertyDescriptor, | ||
) { | ||
const method = descriptor.value | ||
@@ -52,3 +56,3 @@ | ||
export const unless = (...fns: IGenericFunction[]): IDecorator => | ||
function unless(target: any, name: string, descriptor: PropertyDescriptor) { | ||
function unless(_target: any, _name: string, descriptor: PropertyDescriptor) { | ||
const method = descriptor.value | ||
@@ -64,3 +68,7 @@ | ||
export const wrapWith = (decorator: IGenericFunction): IDecorator => | ||
function wrapWith(target: any, name: string, descriptor: PropertyDescriptor) { | ||
function wrapWith( | ||
_target: any, | ||
_name: string, | ||
descriptor: PropertyDescriptor, | ||
) { | ||
descriptor.value = decorator(descriptor.value) | ||
@@ -67,0 +75,0 @@ } |
@@ -25,7 +25,9 @@ /* eslint no-unused-vars: 0 */ | ||
toJSON: true, | ||
} | ||
}, | ||
) { | ||
async function isError(res: Response | any) { | ||
if (!res.ok) { | ||
throw new Error((await res.text()) || `HTTP response was not ok: ${res.status}`) | ||
throw new Error( | ||
(await res.text()) || `HTTP response was not ok: ${res.status}`, | ||
) | ||
} | ||
@@ -46,3 +48,7 @@ return res | ||
function client(endpoint: string, method: HTTPMethod, customConfig: any = {}) { | ||
function client( | ||
endpoint: string, | ||
method: HTTPMethod, | ||
customConfig: any = {}, | ||
) { | ||
const controller = new AbortController() | ||
@@ -62,3 +68,5 @@ const token = localStorage.getItem(options.storageKey) | ||
return { | ||
req: fetch(`${apiEndpoint}${endpoint}`, config).then(isError).then(isJson), | ||
req: fetch(`${apiEndpoint}${endpoint}`, config) | ||
.then(isError) | ||
.then(isJson), | ||
abort: controller.abort.bind(controller), | ||
@@ -73,9 +81,18 @@ } | ||
post(url: string, body: any, options: any) { | ||
return client(url, HTTPMethod.POST, { ...options, body: JSON.stringify(body) }) | ||
return client(url, HTTPMethod.POST, { | ||
...options, | ||
body: JSON.stringify(body), | ||
}) | ||
}, | ||
put(url: string, body: any, options: any) { | ||
return client(url, HTTPMethod.PUT, { ...options, body: JSON.stringify(body) }) | ||
return client(url, HTTPMethod.PUT, { | ||
...options, | ||
body: JSON.stringify(body), | ||
}) | ||
}, | ||
patch(url: string, body: any, options: any) { | ||
return client(url, HTTPMethod.PATCH, { ...options, body: JSON.stringify(body) }) | ||
return client(url, HTTPMethod.PATCH, { | ||
...options, | ||
body: JSON.stringify(body), | ||
}) | ||
}, | ||
@@ -82,0 +99,0 @@ delete(url: string, options: any) { |
@@ -40,9 +40,14 @@ /* eslint no-param-reassign: 0, no-unused-vars: 0 */ | ||
export const liftA2 = curry(<T extends Mappable>(fn: GenericFunction, a1: T, a2: any) => | ||
a1.map(fn).ap(a2) | ||
export const liftA2 = curry( | ||
<T extends Mappable>(fn: GenericFunction, a1: T, a2: any) => | ||
a1.map(fn).ap(a2), | ||
) | ||
export const liftA3 = curry( | ||
<T extends Mappable, P extends Applyable>(fn: GenericFunction, a1: T, a2: P, a3: P) => | ||
a1.map(fn).ap(a2).ap(a3) | ||
<T extends Mappable, P extends Applyable>( | ||
fn: GenericFunction, | ||
a1: T, | ||
a2: P, | ||
a3: P, | ||
) => a1.map(fn).ap(a2).ap(a3), | ||
) | ||
@@ -56,4 +61,4 @@ | ||
a3: P, | ||
a4: P | ||
) => a1.map(fn).ap(a2).ap(a3).ap(a4) | ||
a4: P, | ||
) => a1.map(fn).ap(a2).ap(a3).ap(a4), | ||
) | ||
@@ -65,7 +70,9 @@ | ||
export const flatMap = curry(<F extends FlatMappable>(f: GenericFunction, M: F) => | ||
M.flatMap(f) | ||
export const flatMap = curry( | ||
<F extends FlatMappable>(f: GenericFunction, M: F) => M.flatMap(f), | ||
) | ||
export const fold = curry(<F extends Foldable>(f: GenericFunction, M: F) => M.fold(f)) | ||
export const fold = curry(<F extends Foldable>(f: GenericFunction, M: F) => | ||
M.fold(f), | ||
) | ||
@@ -81,5 +88,11 @@ export const getOrElseThrow = curry((e: Error, M: any) => M.getOrElseThrow(e)) | ||
export const cat = (a: any[], b: any): any[] => a.concat(b) | ||
export const every = curry(<T>(f: (value: T) => boolean, arr: T[]) => arr.every(f)) | ||
export const some = curry(<T>(f: (value: T) => boolean, arr: T[]) => arr.some(f)) | ||
export const find = curry(<T>(f: (value: T) => boolean, arr: T[]) => arr.find(f)) | ||
export const every = curry(<T>(f: (value: T) => boolean, arr: T[]) => | ||
arr.every(f), | ||
) | ||
export const some = curry(<T>(f: (value: T) => boolean, arr: T[]) => | ||
arr.some(f), | ||
) | ||
export const find = curry(<T>(f: (value: T) => boolean, arr: T[]) => | ||
arr.find(f), | ||
) | ||
export const sum = (...args: number[]) => args.reduce((x, y) => x + y, 0) | ||
@@ -95,7 +108,8 @@ export const average = (ns: number[]) => sum(...ns) / ns.length | ||
a: (value: T) => boolean, | ||
b: (value: T) => boolean | ||
b: (value: T) => boolean, | ||
) => | ||
arr.reduce( | ||
(acc, cv) => (a(cv) ? (acc[0].push(cv), acc) : b(cv) ? (acc[1].push(cv), acc) : acc), | ||
[[] as T[], [] as T[]] | ||
(acc, cv) => | ||
a(cv) ? (acc[0].push(cv), acc) : b(cv) ? (acc[1].push(cv), acc) : acc, | ||
[[] as T[], [] as T[]], | ||
) | ||
@@ -120,3 +134,5 @@ | ||
*/ | ||
export const sortBy = curry(<T>(f: (a: T, b: T) => number, a: T[]): T[] => [...a].sort(f)) | ||
export const sortBy = curry(<T>(f: (a: T, b: T) => number, a: T[]): T[] => | ||
[...a].sort(f), | ||
) | ||
@@ -129,3 +145,5 @@ /** | ||
*/ | ||
export const forEach = curry(<T>(f: (value: T) => void, M: T[]): void => M.forEach(f)) | ||
export const forEach = curry(<T>(f: (value: T) => void, M: T[]): void => | ||
M.forEach(f), | ||
) | ||
@@ -135,3 +153,5 @@ /** | ||
*/ | ||
export const map = curry(<T>(f: (value: T, index: number) => any, M: T[]) => M.map(f)) | ||
export const map = curry(<T>(f: (value: T, index: number) => any, M: T[]) => | ||
M.map(f), | ||
) | ||
@@ -141,3 +161,5 @@ /** | ||
*/ | ||
export const filter = curry(<T>(p: (value: T) => boolean, M: T[]) => M.filter(p)) | ||
export const filter = curry(<T>(p: (value: T) => boolean, M: T[]) => | ||
M.filter(p), | ||
) | ||
@@ -149,3 +171,3 @@ /** | ||
<T>(reducer: (accumulator: any, value: T) => any, seed: any, M: T[]) => | ||
M.reduce(reducer, seed) | ||
M.reduce(reducer, seed), | ||
) | ||
@@ -158,3 +180,3 @@ | ||
<T>(reducer: (accumulator: any, value: T) => any, seed: any, M: T[]) => | ||
M.reduceRight(reducer, seed) | ||
M.reduceRight(reducer, seed), | ||
) | ||
@@ -172,4 +194,4 @@ | ||
function innerDeepMap(tree: T[]): any[] { | ||
return Array.prototype.map.call(tree, element => | ||
Array.isArray(element) ? innerDeepMap(element) : fn(element) | ||
return Array.prototype.map.call(tree, (element) => | ||
Array.isArray(element) ? innerDeepMap(element) : fn(element), | ||
) | ||
@@ -181,3 +203,7 @@ } | ||
*/ | ||
export const range = (start: number, end: number, step = start < end ? 1 : -1) => { | ||
export const range = ( | ||
start: number, | ||
end: number, | ||
step = start < end ? 1 : -1, | ||
) => { | ||
let index = -1 | ||
@@ -199,7 +225,9 @@ let length = Math.max(Math.ceil((end - start) / (step || 1)), 0) | ||
*/ | ||
export const deepJoin = curry((keyA: string, keyB: string, a: any[], b: any[]) => { | ||
const objA = keyBy(keyA, a) | ||
const objB = keyBy(keyB, b) | ||
export const deepJoin = curry( | ||
(keyA: string, keyB: string, a: any[], b: any[]) => { | ||
const objA = keyBy(keyA, a) | ||
const objB = keyBy(keyB, b) | ||
return values(aggregate(objA, objB)) | ||
}) | ||
return values(aggregate(objA, objB)) | ||
}, | ||
) |
@@ -12,3 +12,4 @@ /* eslint no-unused-vars: 0 */ | ||
*/ | ||
export const composeAsync = (...fns: GenericFunction[]) => fns.reduce(composeAsync2) | ||
export const composeAsync = (...fns: GenericFunction[]) => | ||
fns.reduce(composeAsync2) | ||
@@ -18,3 +19,4 @@ /** | ||
*/ | ||
export const pipeAsync = (...fns: GenericFunction[]) => fns.reduceRight(composeAsync2) | ||
export const pipeAsync = (...fns: GenericFunction[]) => | ||
fns.reduceRight(composeAsync2) | ||
@@ -30,4 +32,7 @@ /** | ||
*/ | ||
export const reduceAsync = async <T>(f: <X>(value: T) => Promise<X>, init: any, a: T[]) => | ||
await a.reduce((p, val) => p.then(() => f(val)), Promise.resolve(init)) | ||
export const reduceAsync = async <T>( | ||
f: <X>(value: T) => Promise<X>, | ||
init: any, | ||
a: T[], | ||
) => await a.reduce((p, val) => p.then(() => f(val)), Promise.resolve(init)) | ||
@@ -38,2 +43,4 @@ /** | ||
export const filterAsync = async <T>(f: <X>(value: T) => Promise<X>, a: T[]) => | ||
await mapAsync(f, a).then(bools => a.filter((_: any, i: number) => Boolean(bools[i]))) | ||
await mapAsync(f, a).then((bools) => | ||
a.filter((_: any, i: number) => Boolean(bools[i])), | ||
) |
@@ -9,12 +9,25 @@ /* eslint no-unused-vars: 0, no-magic-numbers: 0 */ | ||
export const eq = curry((a: any, b: any) => a === b) | ||
export const add = curry((x: number, y: number) => x + y) | ||
export const addRight = curry((x: number, y: number) => y + x) | ||
export const subtract = curry((x: number, y: number) => x - y) | ||
export const subtractRight = curry((x: number, y: number) => y - x) | ||
export const multiply = curry((x: number, y: number) => x * y) | ||
export const divide = curry((x: number, y: number) => x / y) | ||
export const divideRight = curry((x: number, y: number) => y / x) | ||
export const roundTo = (n: number) => (x: number) => | ||
Math.round(x * Math.pow(10, n)) / Math.pow(10, n) | ||
export const pow = (base: number, power: number): number => | ||
power === 0 ? 1 : power & 1 ? base * pow(base, power - 1) : pow(base * base, power >> 1) | ||
power === 0 | ||
? 1 | ||
: power & 1 | ||
? base * pow(base, power - 1) | ||
: pow(base * base, power >> 1) |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable no-extra-semi */ | ||
/* eslint-disable @typescript-eslint/no-extra-semi */ | ||
/* eslint no-param-reassign: 0, no-unused-vars: 0 */ | ||
@@ -13,3 +15,4 @@ import { curry, unique, compose } from './utils' | ||
(name: PropertyKey, a: GenericObject) => | ||
a && (name in a ? (isFunction(a[name]) ? a[name].call(a) : a[name]) : void 0) | ||
a && | ||
(name in a ? (isFunction(a[name]) ? a[name].call(a) : a[name]) : void 0), | ||
) | ||
@@ -22,3 +25,3 @@ | ||
(name: PropertyKey, value: any, a: GenericObject): GenericObject => | ||
isObject(a) ? ((a[name] = value), a) : a | ||
isObject(a) ? ((a[name] = value), a) : a, | ||
) | ||
@@ -31,3 +34,3 @@ | ||
(name: PropertyKey, value: any, a: GenericObject): GenericObject => | ||
a && name in a ? { ...a, [name]: value } : { ...a } | ||
a && name in a ? { ...a, [name]: value } : { ...a }, | ||
) | ||
@@ -41,3 +44,3 @@ | ||
isMap(a) ? a.set(key, value) : (a[key] = value), a | ||
) | ||
), | ||
) | ||
@@ -50,3 +53,5 @@ | ||
(key: PropertyKey | any, updater: (currentValue: any) => any, a: any) => | ||
isMap(a) ? a.set(key, updater(a.get(key))) : ((a[key] = updater(a[key])), a) | ||
isMap(a) | ||
? a.set(key, updater(a.get(key))) | ||
: ((a[key] = updater(a[key])), a), | ||
) | ||
@@ -58,3 +63,3 @@ | ||
export const props = curry((names: PropertyKey[], a: GenericObject) => | ||
names.map(n => prop(n, a)) | ||
names.map((n) => prop(n, a)), | ||
) | ||
@@ -69,4 +74,4 @@ | ||
key in a ? ((result[key] = a[key]), result) : result, | ||
{} | ||
) | ||
{}, | ||
), | ||
) | ||
@@ -77,7 +82,9 @@ | ||
*/ | ||
export const deepProp = curry((path: string | PropertyKey[], a: GenericObject) => { | ||
if (!Array.isArray(path)) path = path.split('.') | ||
const [p, ...rest] = path | ||
return !rest.length ? prop(p, a) : deepProp(rest, prop(p, a)) | ||
}) | ||
export const deepProp = curry( | ||
(path: string | PropertyKey[], a: GenericObject) => { | ||
if (!Array.isArray(path)) path = path.split('.') | ||
const [p, ...rest] = path | ||
return !rest.length ? prop(p, a) : deepProp(rest, prop(p, a)) | ||
}, | ||
) | ||
@@ -94,3 +101,3 @@ /** | ||
value: any, | ||
obj: GenericObject | ||
obj: GenericObject, | ||
): object { | ||
@@ -117,3 +124,3 @@ if (path.length === 1) { | ||
return innerDeepSetProp(path, value, aux), aux | ||
} | ||
}, | ||
) | ||
@@ -128,3 +135,3 @@ | ||
updater: (currentValue: any) => any, | ||
a: GenericObject | ||
a: GenericObject, | ||
) => { | ||
@@ -136,3 +143,3 @@ if (!Array.isArray(path)) path = path.split('.') | ||
updater: (currentValue: any) => any, | ||
obj: GenericObject | ||
obj: GenericObject, | ||
): object { | ||
@@ -157,3 +164,3 @@ if (path.length === 1) { | ||
return innerDeepSetProp(path, updater, a), a | ||
} | ||
}, | ||
) | ||
@@ -165,3 +172,6 @@ | ||
export const deepPick = curry((paths: PropertyKey[], a: GenericObject) => | ||
paths.reduce((result, path) => deepSetProp(path, deepProp(path)(a), result), {}) | ||
paths.reduce( | ||
(result, path) => deepSetProp(path, deepProp(path)(a), result), | ||
{}, | ||
), | ||
) | ||
@@ -180,3 +190,3 @@ | ||
newObj: GenericObject, | ||
result: GenericObject | ||
result: GenericObject, | ||
) { | ||
@@ -281,3 +291,3 @@ if (oldObj === newObj) return result | ||
if (isArray(a) && isArray(b)) { | ||
return unique(a, b).map(value => deepCopy(value)) | ||
return unique(a, b).map((value) => deepCopy(value)) | ||
} | ||
@@ -384,4 +394,8 @@ | ||
const collisionReducer = (accumulator: any, value: any, index: number, arr: any[]) => | ||
value === arr[index + 1] ? [...accumulator, value] : accumulator | ||
const collisionReducer = ( | ||
accumulator: any, | ||
value: any, | ||
index: number, | ||
arr: any[], | ||
) => (value === arr[index + 1] ? [...accumulator, value] : accumulator) | ||
@@ -398,3 +412,3 @@ const isDescriptor = (obj: any) => obj && (obj.state || obj.methods) | ||
throw new TypeError( | ||
'Unable to concatenate mixins into base object. Object is either not extensible or has been sealed' | ||
'Unable to concatenate mixins into base object. Object is either not extensible or has been sealed', | ||
) | ||
@@ -420,3 +434,3 @@ } | ||
throw new TypeError( | ||
'Unable to concatenate mixins into base object. Object is either not extensible or has been sealed' | ||
'Unable to concatenate mixins into base object. Object is either not extensible or has been sealed', | ||
) | ||
@@ -437,3 +451,3 @@ } | ||
if (obj && typeof obj === 'object' && !Object.isFrozen(obj)) { | ||
Object.getOwnPropertyNames(obj).forEach(name => deepFreeze(obj[name])) | ||
Object.getOwnPropertyNames(obj).forEach((name) => deepFreeze(obj[name])) | ||
Object.freeze(obj) | ||
@@ -479,3 +493,5 @@ } | ||
} else { | ||
Object.getOwnPropertyNames(obj).forEach(prop => (aux[prop] = deepCopy(obj[prop]))) | ||
Object.getOwnPropertyNames(obj).forEach( | ||
(prop) => (aux[prop] = deepCopy(obj[prop])), | ||
) | ||
} | ||
@@ -482,0 +498,0 @@ } |
@@ -91,3 +91,5 @@ /* eslint no-magic-numbers: 0 */ | ||
(isArray(x) && x.length === 0) || | ||
(!isClass(x) && (isSet(x) || isMap(x) || isObject(x)) && values(x).length === 0) || | ||
(!isClass(x) && | ||
(isSet(x) || isMap(x) || isObject(x)) && | ||
values(x).length === 0) || | ||
Number.isNaN(x) | ||
@@ -94,0 +96,0 @@ ) { |
@@ -11,3 +11,5 @@ import { curry } from './utils' | ||
*/ | ||
export const replace = curry((re: RegExp, rpl: string, s: string) => s.replace(re, rpl)) | ||
export const replace = curry((re: RegExp, rpl: string, s: string) => | ||
s.replace(re, rpl), | ||
) | ||
@@ -27,3 +29,3 @@ /** | ||
export const padStart = curry((x: string, reps: number, fill: string) => | ||
String.prototype.padStart.call(x, reps, fill) | ||
String.prototype.padStart.call(x, reps, fill), | ||
) | ||
@@ -35,3 +37,3 @@ | ||
export const padEnd = curry((x: string, reps: number, fill: string) => | ||
String.prototype.padEnd.call(x, reps, fill) | ||
String.prototype.padEnd.call(x, reps, fill), | ||
) |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable no-extra-semi */ | ||
/* eslint-disable @typescript-eslint/no-extra-semi */ | ||
/* eslint complexity: 0, no-unused-vars: 0, eqeqeq: 0, no-magic-numbers: 0 */ | ||
@@ -2,0 +4,0 @@ import { |
@@ -12,3 +12,3 @@ /* eslint no-unused-vars: 0 */ | ||
fn: (element: X) => any, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<any> { | ||
@@ -29,3 +29,3 @@ for (const element of iterable) { | ||
fn: (element: X) => Iterable<any>, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<any> { | ||
@@ -46,3 +46,3 @@ for (const element of iterable) { | ||
fn: (element: X) => boolean, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<X> { | ||
@@ -60,3 +60,5 @@ for (const element of iterable) { | ||
*/ | ||
export const compact = curry(function* compact<X>(iterable: Iterable<X>): Iterable<X> { | ||
export const compact = curry(function* compact<X>( | ||
iterable: Iterable<X>, | ||
): Iterable<X> { | ||
for (const element of iterable) { | ||
@@ -76,3 +78,3 @@ if (element != null) yield element | ||
fn: (element: X) => boolean, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<X> { | ||
@@ -113,3 +115,3 @@ for (const element of iterable) { | ||
numberToTake: number, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<X> { | ||
@@ -133,3 +135,3 @@ const iterator = iterable[Symbol.iterator]() | ||
numberToDrop: number, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): Iterable<X> { | ||
@@ -156,9 +158,9 @@ if (numberToDrop >= (iterable as any).length) return | ||
export function* zip<X>(...iterables: Iterable<X>[]): Iterable<X> { | ||
const iterators = iterables.map(i => i[Symbol.iterator]()) | ||
const iterators = iterables.map((i) => i[Symbol.iterator]()) | ||
while (true) { | ||
const pairs = iterators.map(j => j.next()) | ||
const pairs = iterators.map((j) => j.next()) | ||
const dones: (boolean | undefined)[] = [] | ||
const values: any[] = [] | ||
pairs.forEach(p => (dones.push(p.done), values.push(p.value))) | ||
pairs.forEach((p) => (dones.push(p.done), values.push(p.value))) | ||
if (dones.indexOf(true) >= 0) break | ||
@@ -180,9 +182,9 @@ yield values as any | ||
): Iterable<any> { | ||
const iterators = iterables.map(i => i[Symbol.iterator]()) | ||
const iterators = iterables.map((i) => i[Symbol.iterator]()) | ||
while (true) { | ||
const pairs = iterators.map(j => j.next()) | ||
const pairs = iterators.map((j) => j.next()) | ||
const dones: (boolean | undefined)[] = [] | ||
const values: any[] = [] | ||
pairs.forEach(p => (dones.push(p.done), values.push(p.value))) | ||
pairs.forEach((p) => (dones.push(p.done), values.push(p.value))) | ||
if (dones.indexOf(true) >= 0) break | ||
@@ -203,3 +205,3 @@ yield zipper(...values) | ||
seed: any, | ||
iterable: Iterable<X> | ||
iterable: Iterable<X>, | ||
): any { | ||
@@ -219,3 +221,3 @@ let accumulator = seed | ||
export function memoizeIter( | ||
generator: (...args: any) => Generator | ||
generator: (...args: any) => Generator, | ||
): (...args: any) => Generator { | ||
@@ -222,0 +224,0 @@ const memos = Object.create(null) |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable no-extra-semi */ | ||
/* eslint-disable @typescript-eslint/no-extra-semi */ | ||
/* eslint no-unused-vars: 0, prefer-const: 0, no-param-reassign: 0 */ | ||
@@ -38,3 +40,3 @@ /** | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -46,3 +48,3 @@ }, | ||
reducer: (accumulator: any, element: any) => any, | ||
seed: any | ||
seed: any, | ||
): any { | ||
@@ -69,3 +71,3 @@ const iterator = (this as any)[Symbol.iterator]() | ||
do { | ||
({ done, value } = iterator.next()) | ||
;({ done, value } = iterator.next()) | ||
} while (!done && !predicate(value)) | ||
@@ -77,3 +79,3 @@ return { done, value } | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -91,3 +93,3 @@ }, | ||
do { | ||
({ done, value } = iterator.next()) | ||
;({ done, value } = iterator.next()) | ||
} while (!done && !searcher(value)) | ||
@@ -99,3 +101,3 @@ return { done, value } | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -118,3 +120,3 @@ }, | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -136,3 +138,3 @@ }, | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -156,3 +158,3 @@ }, | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -184,3 +186,3 @@ }, | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -229,3 +231,3 @@ | ||
}, | ||
Collection | ||
Collection, | ||
) | ||
@@ -232,0 +234,0 @@ |
@@ -22,3 +22,6 @@ export const ClassMixin = (behaviour: any, sharedBehaviour: any = {}) => { | ||
value: sharedBehaviour[property], | ||
enumerable: Object.prototype.propertyIsEnumerable.call(sharedBehaviour, property), | ||
enumerable: Object.prototype.propertyIsEnumerable.call( | ||
sharedBehaviour, | ||
property, | ||
), | ||
}) | ||
@@ -25,0 +28,0 @@ } |
@@ -25,3 +25,6 @@ /** | ||
value: (sharedBehaviour as any)[property], | ||
enumerable: Object.prototype.propertyIsEnumerable.call(sharedBehaviour, property), | ||
enumerable: Object.prototype.propertyIsEnumerable.call( | ||
sharedBehaviour, | ||
property, | ||
), | ||
}) | ||
@@ -28,0 +31,0 @@ } |
@@ -18,3 +18,3 @@ /* eslint no-unused-vars: 0 */ | ||
get messages() { | ||
return this.errors.map(e => e.message) | ||
return this.errors.map((e) => e.message) | ||
} | ||
@@ -39,10 +39,12 @@ } | ||
onSucces: (...args: any) => any, | ||
onFailure: (...args: any) => any | ||
onFailure: (...args: any) => any, | ||
) => | ||
function validate(this: any, ...args: any[]) { | ||
if (!validator(selector.apply(this, args))) { | ||
return onFailure(new ValidationError('Validation failed', validator.errors)) | ||
return onFailure( | ||
new ValidationError('Validation failed', validator.errors), | ||
) | ||
} | ||
return onSucces.apply(this, args) | ||
} | ||
}, | ||
) |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint prefer-rest-params: 0, prefer-spread: 0, no-unused-vars: 0 */ | ||
@@ -50,3 +51,7 @@ import { deepEqual } from '../functions/utils' | ||
if (handler === undefined) { | ||
return { key: DEFAULT_METHOD, handler: key, [isMethodObject]: true } as IHandler | ||
return { | ||
key: DEFAULT_METHOD, | ||
handler: key, | ||
[isMethodObject]: true, | ||
} as IHandler | ||
} | ||
@@ -66,3 +71,5 @@ return { key, handler, [isMethodObject]: true } as IHandler | ||
function multiMethod() { | ||
let method: (...args: any[]) => any = initialHandler(multiMethod[handlersKey]) | ||
let method: (...args: any[]) => any = initialHandler( | ||
multiMethod[handlersKey], | ||
) | ||
@@ -83,6 +90,10 @@ for (let i = 0; i < multiMethod[handlersKey].length; i++) { | ||
if (method) { | ||
return typeof method === 'function' ? method.apply(null, arguments as any) : method | ||
return typeof method === 'function' | ||
? method.apply(null, arguments as any) | ||
: method | ||
} | ||
throw new NoHandlerError(`No handlers for args (${JSON.stringify(arguments)})`) | ||
throw new NoHandlerError( | ||
`No handlers for args (${JSON.stringify(arguments)})`, | ||
) | ||
} | ||
@@ -110,3 +121,5 @@ | ||
multiMethod[dispatchKey] = dispatch | ||
multiMethod[handlersKey] = defaultMethod ? methods.concat(defaultMethod) : methods | ||
multiMethod[handlersKey] = defaultMethod | ||
? methods.concat(defaultMethod) | ||
: methods | ||
@@ -123,4 +136,4 @@ multiMethod.map = function map(fn: (...args: any) => any) { | ||
}, | ||
} as IHandler) | ||
) | ||
} as IHandler), | ||
), | ||
) | ||
@@ -135,4 +148,4 @@ } | ||
multiMethod[dispatchKey] as any, | ||
...methods.concat(multiMethod[handlersKey]) | ||
...methods.concat(multiMethod[handlersKey]), | ||
) | ||
} |
@@ -20,3 +20,3 @@ import { placeholder, withNext } from './utils' | ||
} | ||
}) | ||
}), | ||
) | ||
@@ -23,0 +23,0 @@ return () => subs.unsubscribe() |
@@ -16,5 +16,5 @@ /* eslint no-unused-vars: 0 */ | ||
retry(handler, stream, sub, observer) | ||
return () => sub.map(s => s.unsubscribe()) | ||
return () => sub.map((s) => s.unsubscribe()) | ||
}) | ||
} | ||
}, | ||
) | ||
@@ -26,3 +26,3 @@ | ||
sub: Subscription[], | ||
observer: Observer | ||
observer: Observer, | ||
): any { | ||
@@ -32,3 +32,3 @@ sub.pop()?.unsubscribe() | ||
stream.subscribe({ | ||
next: value => observer.next(value), | ||
next: (value) => observer.next(value), | ||
error: (err: Error) => { | ||
@@ -46,4 +46,4 @@ try { | ||
complete: () => observer.complete(), | ||
}) | ||
}), | ||
) | ||
} |
@@ -16,6 +16,9 @@ import { values } from '../../functions/objects' | ||
function pushResults(event: { stream: number; value: any }, observer: Observer) { | ||
function pushResults( | ||
event: { stream: number; value: any }, | ||
observer: Observer, | ||
) { | ||
store[event.stream].push(event.value) | ||
if (buffers.every(buffer => buffer.length)) { | ||
buffers.forEach(buffer => { | ||
if (buffers.every((buffer: any) => buffer.length)) { | ||
buffers.forEach((buffer) => { | ||
observer.next(buffer.pop()) | ||
@@ -30,9 +33,9 @@ buffer.length = 0 | ||
stream.subscribe({ | ||
next: value => pushResults({ stream: i, value }, observer), | ||
next: (value) => pushResults({ stream: i, value }, observer), | ||
error: observer.error.bind(observer), | ||
complete: () => ++done === streams.length && observer.complete(), | ||
}) | ||
}), | ||
) | ||
return () => subscriptions.forEach(subs => subs.unsubscribe()) | ||
return () => subscriptions.forEach((subs) => subs.unsubscribe()) | ||
}) | ||
}) |
@@ -12,3 +12,3 @@ import { Observable, Observer, Subscription } from '../Observable' | ||
subNextStream(streams, 0, subs, observer) | ||
return () => subs.forEach(sub => sub.unsubscribe()) | ||
return () => subs.forEach((sub) => sub.unsubscribe()) | ||
}) | ||
@@ -21,7 +21,7 @@ }) | ||
subs: Subscription[], | ||
observer: Observer | ||
observer: Observer, | ||
) { | ||
subs.push( | ||
streams[i].subscribe({ | ||
next: value => observer.next(value), | ||
next: (value) => observer.next(value), | ||
error: observer.error.bind(observer), | ||
@@ -32,4 +32,4 @@ complete() { | ||
}, | ||
}) | ||
}), | ||
) | ||
} |
@@ -17,3 +17,3 @@ import { last } from '../../functions/arrays' | ||
const subs = stream.subscribe({ | ||
next: value => { | ||
next: (value) => { | ||
stack.push(value) | ||
@@ -20,0 +20,0 @@ clearTimeout(lastInterval) |
@@ -11,21 +11,23 @@ /* eslint no-unused-vars: 0 */ | ||
*/ | ||
export const distinct = placeholder((fn: (value: any) => any, stream: Observable) => { | ||
let lastSent: any = null | ||
return new Observable((observer: Observer) => { | ||
const subs = stream.subscribe( | ||
withNext(observer)((value: any) => { | ||
try { | ||
const a = fn(lastSent) | ||
const b = fn(value) | ||
if (!deepEqual(a, b)) { | ||
export const distinct = placeholder( | ||
(fn: (value: any) => any, stream: Observable) => { | ||
let lastSent: any = null | ||
return new Observable((observer: Observer) => { | ||
const subs = stream.subscribe( | ||
withNext(observer)((value: any) => { | ||
try { | ||
const a = fn(lastSent) | ||
const b = fn(value) | ||
if (!deepEqual(a, b)) { | ||
observer.next(value) | ||
} | ||
} catch { | ||
observer.next(value) | ||
} | ||
} catch { | ||
observer.next(value) | ||
} | ||
lastSent = value | ||
}) | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}) | ||
lastSent = value | ||
}), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}, | ||
) |
@@ -22,6 +22,6 @@ /* eslint no-unused-vars: 0 */ | ||
} | ||
}) | ||
}), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -23,6 +23,6 @@ /* eslint no-unused-vars: 0 */ | ||
} | ||
}) | ||
}), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -15,4 +15,4 @@ /* eslint no-unused-vars: 0 */ | ||
const subs = stream.subscribe({ | ||
next: value => observer.next(value), | ||
error: err => { | ||
next: (value) => observer.next(value), | ||
error: (err) => { | ||
try { | ||
@@ -37,3 +37,3 @@ fn(err) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -18,3 +18,3 @@ /* eslint no-unused-vars: 0 */ | ||
const initialSub = stream.subscribe({ | ||
next: value => { | ||
next: (value) => { | ||
try { | ||
@@ -35,3 +35,3 @@ handleNext(fn(value)) | ||
nextObs.subscribe({ | ||
next: value => observer.next(value), | ||
next: (value) => observer.next(value), | ||
complete: () => { | ||
@@ -41,3 +41,3 @@ pending -= 1 | ||
}, | ||
} as Observer) | ||
} as Observer), | ||
) | ||
@@ -47,6 +47,6 @@ } | ||
initialSub.unsubscribe(), | ||
subs.forEach(sub => sub.unsubscribe()), | ||
subs.forEach((sub) => sub.unsubscribe()), | ||
observer.complete() | ||
) | ||
}) | ||
}), | ||
) |
@@ -21,6 +21,6 @@ /* eslint no-unused-vars: 0 */ | ||
} | ||
}) | ||
}), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -13,5 +13,7 @@ import { withNext, placeholder } from './utils' | ||
new Observable((observer: Observer) => { | ||
const subs = stream.subscribe(withNext(observer)(() => observer.next(value))) | ||
const subs = stream.subscribe( | ||
withNext(observer)(() => observer.next(value)), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -13,11 +13,11 @@ import { placeholder } from './utils' | ||
return new Observable((observer: Observer) => { | ||
const subscriptions = streams.map(stream => | ||
const subscriptions = streams.map((stream) => | ||
stream.subscribe({ | ||
next: value => observer.next(value), | ||
next: (value) => observer.next(value), | ||
error: observer.error.bind(observer), | ||
complete: () => ++done === streams.length && observer.complete(), | ||
}) | ||
}), | ||
) | ||
return () => subscriptions.forEach(subs => subs.unsubscribe()) | ||
return () => subscriptions.forEach((subs) => subs.unsubscribe()) | ||
}) | ||
}) |
@@ -15,6 +15,6 @@ import { deepProp } from '../../functions/objects' | ||
const subs = stream.subscribe( | ||
withNext(observer)((obj: any) => observer.next(deepProp(key, obj))) | ||
withNext(observer)((obj: any) => observer.next(deepProp(key, obj))), | ||
) | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -16,3 +16,3 @@ /* eslint no-unused-vars: 0 */ | ||
initialValue: any, | ||
stream: Observable | ||
stream: Observable, | ||
) => { | ||
@@ -39,3 +39,3 @@ let accumulator = initialValue ?? {} | ||
}) | ||
} | ||
}, | ||
) |
@@ -36,3 +36,3 @@ /* eslint no-param-reassign: 0, no-magic-numbers: 0 */ | ||
retryInner(stream, observer, sub, config, 1) | ||
return () => sub.map(s => s.unsubscribe()) | ||
return () => sub.map((s) => s.unsubscribe()) | ||
}) | ||
@@ -46,3 +46,3 @@ }) | ||
config: IRetryConfig, | ||
i: number | ||
i: number, | ||
): void { | ||
@@ -52,3 +52,3 @@ sub.pop()?.unsubscribe() | ||
stream.subscribe({ | ||
next: value => observer.next(value), | ||
next: (value) => observer.next(value), | ||
error: () => { | ||
@@ -58,3 +58,5 @@ if (i <= config.retries) { | ||
() => retryInner(stream, observer, sub, config, i + 1), | ||
config.method === 'expo' ? config.delay * Math.pow(i, 2) : config.delay * i | ||
config.method === 'expo' | ||
? config.delay * Math.pow(i, 2) | ||
: config.delay * i, | ||
) | ||
@@ -65,4 +67,4 @@ } | ||
complete: () => observer.complete(), | ||
}) | ||
}), | ||
) | ||
} |
@@ -19,3 +19,6 @@ /* eslint no-unused-vars: 0 */ | ||
*/ | ||
export const share = (bufferSize: number = DEFAULT_BUFFER_SIZE, stream: Observable) => { | ||
export const share = ( | ||
bufferSize: number = DEFAULT_BUFFER_SIZE, | ||
stream: Observable, | ||
) => { | ||
const store: IStore = { | ||
@@ -30,7 +33,7 @@ values: [], | ||
removeObserver(o) { | ||
this.observers = this.observers.filter(ob => ob !== o) | ||
this.observers = this.observers.filter((ob) => ob !== o) | ||
}, | ||
} | ||
const subs = stream.subscribe({ | ||
next: value => { | ||
next: (value) => { | ||
if (store.values.length >= bufferSize) { | ||
@@ -42,3 +45,3 @@ store.values.shift() | ||
}, | ||
error: error => { | ||
error: (error) => { | ||
if (store.errors.length >= bufferSize) { | ||
@@ -56,4 +59,4 @@ store.errors.shift() | ||
if (errors.length) { | ||
observers.forEach(observer => { | ||
errors.forEach(value => { | ||
observers.forEach((observer) => { | ||
errors.forEach((value) => { | ||
observer.error(value) | ||
@@ -64,4 +67,4 @@ }) | ||
} else { | ||
observers.forEach(observer => { | ||
values.forEach(value => { | ||
observers.forEach((observer) => { | ||
values.forEach((value) => { | ||
observer.next(value) | ||
@@ -74,3 +77,3 @@ }) | ||
if (wantsComplete) { | ||
observers.forEach(observer => observer.complete()) | ||
observers.forEach((observer) => observer.complete()) | ||
subs.unsubscribe() | ||
@@ -90,4 +93,4 @@ } | ||
} | ||
}) | ||
}), | ||
)() | ||
} |
@@ -15,3 +15,3 @@ import { withNext, placeholder } from './utils' | ||
} | ||
}) | ||
}), | ||
) | ||
@@ -18,0 +18,0 @@ return () => subs.unsubscribe() |
@@ -16,3 +16,3 @@ /* eslint no-param-reassign: 0 */ | ||
return (...args: any[]) => | ||
subs.forEach(observer => (observer as any)[prop](...args)) | ||
subs.forEach((observer) => (observer as any)[prop](...args)) | ||
} | ||
@@ -41,4 +41,4 @@ if (prop === 'subscribe') { | ||
}, | ||
} | ||
}, | ||
) | ||
} |
@@ -29,3 +29,3 @@ import { placeholder } from './utils' | ||
} | ||
}) | ||
}), | ||
) |
@@ -17,3 +17,3 @@ import { withNext, placeholder } from './utils' | ||
return observer.next(value) | ||
}) | ||
}), | ||
) | ||
@@ -20,0 +20,0 @@ return () => subs.unsubscribe() |
@@ -28,3 +28,3 @@ import { withNext, placeholder } from './utils' | ||
} | ||
}) | ||
}), | ||
) | ||
@@ -31,0 +31,0 @@ return () => subs.unsubscribe() |
@@ -15,3 +15,3 @@ /* eslint no-unused-vars: 0 */ | ||
const subs = stream.subscribe({ | ||
next: value => { | ||
next: (value) => { | ||
try { | ||
@@ -28,3 +28,3 @@ if (comparator(value)) { | ||
return () => subs.unsubscribe() | ||
}) | ||
}), | ||
) |
@@ -21,3 +21,3 @@ /* eslint no-unused-vars: 0 */ | ||
}, | ||
} | ||
}, | ||
) |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable no-extra-semi */ | ||
/* eslint-disable @typescript-eslint/no-extra-semi */ | ||
/* eslint prefer-rest-params: 0, prefer-spread: 0 */ | ||
@@ -2,0 +4,0 @@ import { |
@@ -24,5 +24,5 @@ import { values } from '../../functions/objects' | ||
buffers[event.n].unshift(event.value) | ||
if (buffers.every(buffer => buffer.length > 0)) { | ||
if (buffers.every((buffer: any) => buffer.length > 0)) { | ||
try { | ||
observer.next(zipper(...buffers.map(buffer => buffer.pop()))) | ||
observer.next(zipper(...buffers.map((buffer) => buffer.pop()))) | ||
} catch (err: any) { | ||
@@ -37,9 +37,9 @@ observer.error(err) | ||
stream.subscribe({ | ||
next: value => pushValue({ n: i, value }, observer), | ||
next: (value) => pushValue({ n: i, value }, observer), | ||
error: observer.error.bind(observer), | ||
complete: () => ++done === streams.length && observer.complete(), | ||
}) | ||
}), | ||
) | ||
return () => subscriptions.forEach(subs => subs.unsubscribe()) | ||
return () => subscriptions.forEach((subs) => subs.unsubscribe()) | ||
}) | ||
}) |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint no-unused-vars: 0, no-magic-numbers: 0 */ | ||
@@ -60,3 +61,6 @@ import { entries } from '../functions/objects' | ||
take(numberToTake: number): Observable | ||
reduce(reducer: (accumulator: any, value: any) => any, initialValue: any): Observable | ||
reduce( | ||
reducer: (accumulator: any, value: any) => any, | ||
initialValue: any, | ||
): Observable | ||
mapTo(value: any): Observable | ||
@@ -88,3 +92,4 @@ throttle(limit: number): Observable | ||
export const $$observable = /* #__PURE__ */ (() => | ||
(typeof Symbol === 'function' && (Symbol as any).observable) || '@@observable')() | ||
(typeof Symbol === 'function' && (Symbol as any).observable) || | ||
'@@observable')() | ||
@@ -100,8 +105,10 @@ const additionalProperties = { | ||
]) | ||
entries(group as any).forEach(([event, handler]) => emitter.on(event, handler)) | ||
entries(group as any).forEach(([event, handler]) => | ||
emitter.on(event, handler), | ||
) | ||
return () => | ||
entries(group as any).forEach(([event, handler]) => | ||
emitter.removeListener(event, handler) | ||
emitter.removeListener(event, handler), | ||
) | ||
}) | ||
}), | ||
), | ||
@@ -115,3 +122,3 @@ fromGenerator: placeholder( | ||
.on('error', observer.error.bind(observer)) | ||
}) | ||
}), | ||
), | ||
@@ -122,6 +129,6 @@ fromPromise: placeholder( | ||
promise | ||
.then(value => observer.next(value)) | ||
.catch(err => observer.error(err)) | ||
.then((value) => observer.next(value)) | ||
.catch((err) => observer.error(err)) | ||
.finally(() => observer.complete()) | ||
}) | ||
}), | ||
), | ||
@@ -134,3 +141,3 @@ fromStream: placeholder( | ||
stream.on('error', observer.error.bind(observer)) | ||
}) | ||
}), | ||
), | ||
@@ -172,3 +179,6 @@ combine, | ||
}, | ||
reduce(reducer: (accumulator: any, value: any) => any, initialValue: any = {}) { | ||
reduce( | ||
reducer: (accumulator: any, value: any) => any, | ||
initialValue: any = {}, | ||
) { | ||
return reduce(reducer, initialValue, this) | ||
@@ -175,0 +185,0 @@ }, |
@@ -13,3 +13,4 @@ /* eslint no-unused-vars: 0 */ | ||
function createActionListenerMiddleware() { | ||
const listeners: Map<IActionCreator | string | IAction, IListener[]> = new Map() | ||
const listeners: Map<IActionCreator | string | IAction, IListener[]> = | ||
new Map() | ||
@@ -33,3 +34,5 @@ /** | ||
actionCreator, | ||
currentListeners.filter((currentListener: IListener) => currentListener !== listener) | ||
currentListeners.filter( | ||
(currentListener: IListener) => currentListener !== listener, | ||
), | ||
) | ||
@@ -36,0 +39,0 @@ } |
@@ -29,3 +29,3 @@ /* eslint no-unused-vars: 0, @typescript-eslint/no-unused-vars: 0 */ | ||
const chain = middlewares.map(middleware => middleware(middlewareAPI)) | ||
const chain = middlewares.map((middleware) => middleware(middlewareAPI)) | ||
dispatch = compose(...chain)(store.dispatch) | ||
@@ -32,0 +32,0 @@ |
@@ -22,3 +22,3 @@ /* eslint no-unused-vars: 0 */ | ||
payloadCreator: (...args: any[]) => any, | ||
options: any | ||
options: any, | ||
) { | ||
@@ -38,3 +38,3 @@ // Create thunk states | ||
getState: () => any, | ||
extra: any | ||
extra: any, | ||
) { | ||
@@ -54,3 +54,3 @@ const requestId = nanoid() | ||
abortController.signal.addEventListener('abort', () => | ||
reject(new AbortError(abortReason || 'Aborted')) | ||
reject(new AbortError(abortReason || 'Aborted')), | ||
) | ||
@@ -79,4 +79,7 @@ }) | ||
arg, | ||
options?.getPendingMeta?.({ requestId, arg }, { getState, extra }) | ||
) | ||
options?.getPendingMeta?.( | ||
{ requestId, arg }, | ||
{ getState, extra }, | ||
), | ||
), | ||
) | ||
@@ -111,3 +114,3 @@ | ||
return fulfilled(result, requestId, arg) | ||
}) | ||
}), | ||
) | ||
@@ -150,3 +153,8 @@ | ||
return Object.assign(actionCreator, { pending, rejected, fulfilled, typePrefix }) | ||
return Object.assign(actionCreator, { | ||
pending, | ||
rejected, | ||
fulfilled, | ||
typePrefix, | ||
}) | ||
} | ||
@@ -191,3 +199,3 @@ | ||
}, | ||
}) | ||
}), | ||
) | ||
@@ -209,11 +217,14 @@ } | ||
*/ | ||
return createAction(typePrefix + '/' + STATUS_PENDING, (requestId, arg, meta) => ({ | ||
payload: undefined, | ||
meta: { | ||
...(meta || {}), | ||
arg, | ||
requestId, | ||
requestStatus: STATUS_PENDING, | ||
}, | ||
})) | ||
return createAction( | ||
typePrefix + '/' + STATUS_PENDING, | ||
(requestId, arg, meta) => ({ | ||
payload: undefined, | ||
meta: { | ||
...(meta || {}), | ||
arg, | ||
requestId, | ||
requestStatus: STATUS_PENDING, | ||
}, | ||
}), | ||
) | ||
} | ||
@@ -250,4 +261,4 @@ | ||
}, | ||
}) | ||
}), | ||
) | ||
} |
@@ -16,3 +16,3 @@ /* eslint no-unused-vars: 0 */ | ||
actionCreators: IActionCreatorObject | IActionCreator, | ||
dispatch: (action: IAction) => any | ||
dispatch: (action: IAction) => any, | ||
) { | ||
@@ -25,3 +25,3 @@ if (isFunction(actionCreators)) { | ||
throw new Error( | ||
'Expected an object or function, but got: ' + stringify(actionCreators) | ||
'Expected an object or function, but got: ' + stringify(actionCreators), | ||
) | ||
@@ -45,3 +45,3 @@ } | ||
actionCreator: IActionCreator, | ||
dispatch: (action: IAction) => any | ||
dispatch: (action: IAction) => any, | ||
) { | ||
@@ -59,4 +59,4 @@ return Object.assign( | ||
}, | ||
} | ||
}, | ||
) as any as IActionCreator | ||
} |
@@ -57,3 +57,3 @@ /* eslint no-param-reassign: 0 */ | ||
`When called with action of type ${actionType} ` + | ||
`the reducer for key ${key} returned undefined.` | ||
`the reducer for key ${key} returned undefined.`, | ||
) | ||
@@ -82,3 +82,3 @@ } | ||
'Set null for the return value if you do not ' + | ||
'want to set a value for this reducer.' | ||
'want to set a value for this reducer.', | ||
) | ||
@@ -85,0 +85,0 @@ } |
@@ -21,3 +21,6 @@ /* eslint no-unused-vars: 0 */ | ||
*/ | ||
export function createAction(type: string, prepareAction: (...args: any[]) => any) { | ||
export function createAction( | ||
type: string, | ||
prepareAction: (...args: any[]) => any, | ||
) { | ||
function actionCreator(...args: any[]) { | ||
@@ -24,0 +27,0 @@ if (prepareAction) { |
@@ -19,3 +19,3 @@ /* eslint no-unused-vars: 0, prefer-spread: 0, prefer-rest-params: 0 */ | ||
`createSelector expects an output function after the ` + | ||
`inputs, but received: ${resultFunc}` | ||
`inputs, but received: ${resultFunc}`, | ||
) | ||
@@ -57,3 +57,5 @@ } | ||
if (!dependencies.every(isFunction)) { | ||
throw new Error('createSelector expects all input-selectors to be functions') | ||
throw new Error( | ||
'createSelector expects all input-selectors to be functions', | ||
) | ||
} | ||
@@ -60,0 +62,0 @@ |
@@ -23,3 +23,5 @@ /* eslint no-param-reassign: 0, no-unused-vars: 0 */ | ||
initialState?: any, | ||
enhancer?: (createStore: any) => (reducer: IReducerFunction, initialState: any) => any | ||
enhancer?: ( | ||
createStore: any, | ||
) => (reducer: IReducerFunction, initialState: any) => any, | ||
) { | ||
@@ -37,3 +39,5 @@ if (isFunction(initialState) && isFunction(enhancer)) { | ||
if (!isFunction(enhancer)) { | ||
throw new Error('Expected enhancer to be a function, got: ' + stringify(enhancer)) | ||
throw new Error( | ||
'Expected enhancer to be a function, got: ' + stringify(enhancer), | ||
) | ||
} | ||
@@ -45,3 +49,5 @@ | ||
if (!isFunction(reducer)) { | ||
throw new Error('Expected reducer to be a function, got: ' + stringify(reducer)) | ||
throw new Error( | ||
'Expected reducer to be a function, got: ' + stringify(reducer), | ||
) | ||
} | ||
@@ -79,9 +85,16 @@ | ||
*/ | ||
function subscribe(selector: (state: any) => any, listener: (state: any) => void) { | ||
function subscribe( | ||
selector: (state: any) => any, | ||
listener: (state: any) => void, | ||
) { | ||
if (!isFunction(selector)) { | ||
throw new Error('Expected selector to be a function, got: ' + stringify(selector)) | ||
throw new Error( | ||
'Expected selector to be a function, got: ' + stringify(selector), | ||
) | ||
} | ||
if (!isFunction(listener)) { | ||
throw new Error('Expected listener to be a function, got: ' + stringify(listener)) | ||
throw new Error( | ||
'Expected listener to be a function, got: ' + stringify(listener), | ||
) | ||
} | ||
@@ -108,3 +121,3 @@ | ||
ensureCanMutateNextListeners() | ||
const index = nextListeners.findIndex(obj => obj.listener === listener) | ||
const index = nextListeners.findIndex((obj) => obj.listener === listener) | ||
nextListeners.splice(index, 1) | ||
@@ -111,0 +124,0 @@ currentListeners = null |
/* eslint no-magic-numbers: 0, no-param-reassign: 0 */ | ||
const urlAlphabet = 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW' | ||
const urlAlphabet = | ||
'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW' | ||
@@ -4,0 +5,0 @@ /** |
@@ -0,4 +1,10 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint no-unused-vars: 0 */ | ||
import { isFunction } from '../functions/predicates' | ||
import { multi, method, MultiMethod, IHandler } from '../multimethod/multimethod' | ||
import { | ||
multi, | ||
method, | ||
MultiMethod, | ||
IHandler, | ||
} from '../multimethod/multimethod' | ||
import { combineReducers } from './combineReducers' | ||
@@ -17,3 +23,6 @@ import { IAction } from './createAction' | ||
interface IReducerBuilder { | ||
case(type: string, handler: (state: any, action: IAction) => any): IReducerBuilder | ||
case( | ||
type: string, | ||
handler: (state: any, action: IAction) => any, | ||
): IReducerBuilder | ||
init(initialState: any): IReducerBuilder | ||
@@ -36,3 +45,6 @@ build(): MultiMethod | ||
cases.push( | ||
method((state: any, action: IAction) => action.type === type, handler) | ||
method( | ||
(_state: any, action: IAction) => action.type === type, | ||
handler, | ||
), | ||
) | ||
@@ -39,0 +51,0 @@ } |
@@ -12,3 +12,5 @@ import { isFunction } from '../functions/predicates' | ||
return (next: Middleware) => (action: IAction | any) => | ||
isFunction(action) ? action(dispatch, getState, extraArgument) : next(action) | ||
isFunction(action) | ||
? action(dispatch, getState, extraArgument) | ||
: next(action) | ||
} | ||
@@ -15,0 +17,0 @@ middleware.withExtraArgument = createThunkMiddleware |
@@ -0,1 +1,2 @@ | ||
/* eslint-disable no-redeclare */ | ||
/* eslint no-unused-vars: 0 */ | ||
@@ -7,3 +8,3 @@ import { Transform } from 'stream' | ||
objectMode: true, | ||
transform(chunk: any, encoding: string, callback: () => void) { | ||
transform(chunk: any, _encoding: string, callback: () => void) { | ||
if (fn(chunk)) this.push(chunk) | ||
@@ -18,3 +19,3 @@ callback() | ||
objectMode: true, | ||
transform(chunk: any, encoding: string, callback: () => void) { | ||
transform(chunk: any, _encoding: string, callback: () => void) { | ||
this.push(fn(chunk)) | ||
@@ -28,3 +29,3 @@ callback() | ||
reducer: (accumulator: any, value: any) => any, | ||
initialValue: any | ||
initialValue: any, | ||
) { | ||
@@ -34,3 +35,3 @@ let accumulator = initialValue | ||
objectMode: true, | ||
transform(chunk: any, encoding: string, callback: () => void) { | ||
transform(chunk: any, _encoding: string, callback: () => void) { | ||
accumulator = reducer(accumulator, chunk) | ||
@@ -61,5 +62,5 @@ callback() | ||
push: (value: any) => any, | ||
onComplete: (err: Error) => any | ||
onComplete: (err: Error) => any, | ||
) => void, | ||
options = {} | ||
options = {}, | ||
) { | ||
@@ -72,3 +73,8 @@ super({ ...options, objectMode: true }) | ||
this.running++ | ||
this.userTransform(chunk, encoding, this.push.bind(this), this._onComplete.bind(this)) | ||
this.userTransform( | ||
chunk, | ||
encoding, | ||
this.push.bind(this), | ||
this._onComplete.bind(this), | ||
) | ||
callback() | ||
@@ -113,5 +119,5 @@ } | ||
push: (value: any) => any, | ||
onComplete: (err: Error) => any | ||
onComplete: (err: Error) => any, | ||
) => void, | ||
options = {} | ||
options = {}, | ||
) { | ||
@@ -125,3 +131,8 @@ super({ ...options, objectMode: true }) | ||
this.running++ | ||
this.userTransform(chunk, encoding, this.push.bind(this), this._onComplete.bind(this)) | ||
this.userTransform( | ||
chunk, | ||
encoding, | ||
this.push.bind(this), | ||
this._onComplete.bind(this), | ||
) | ||
if (this.running < this.concurrency) { | ||
@@ -156,3 +167,3 @@ callback() | ||
export function createFork(stream: any) { | ||
return (...streams: any[]) => streams.forEach(s => stream.pipe(s)) | ||
return (...streams: any[]) => streams.forEach((s) => stream.pipe(s)) | ||
} | ||
@@ -163,3 +174,3 @@ | ||
let endCount = 0 | ||
return sources.map(source => { | ||
return sources.map((source) => { | ||
source.on('end', () => { | ||
@@ -166,0 +177,0 @@ if (++endCount === sources.length) dest.end() |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
931063
13264
13