@teleology/fp
Advanced tools
Comparing version 2.0.3 to 3.0.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.objecToEquality = void 0; | ||
const { | ||
get | ||
} = require('./pick'); | ||
const objecToEquality = obj => src => { | ||
const keys = Object.keys(obj); | ||
for (const key of keys) { | ||
if (get(key)(src) !== obj[key]) { | ||
return false; | ||
const pick_1 = require("./pick"); | ||
const objecToEquality = (obj) => (src) => { | ||
const keys = Object.keys(obj); | ||
for (const key of keys) { | ||
if ((0, pick_1.get)(key)(src) !== obj[key]) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
return true; | ||
}; | ||
exports.objecToEquality = objecToEquality; | ||
exports.objecToEquality = objecToEquality; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clean = exports.empty = void 0; | ||
const is = arg => Object.prototype.toString.call(arg).slice(8, -1); | ||
const empty = v => { | ||
const t = is(v); | ||
return t === `String` && v.length === 0 || t === `Object` && Object.keys(v).length === 0 || t === `Array` && v.length === 0 || v === null || v === undefined; | ||
const is = (arg) => Object.prototype.toString.call(arg).slice(8, -1); | ||
const empty = (v) => { | ||
const t = is(v); | ||
return ((t === `String` && v.length === 0) || | ||
(t === `Object` && Object.keys(v).length === 0) || | ||
(t === `Array` && v.length === 0) || | ||
v === null || | ||
v === undefined); | ||
}; | ||
exports.empty = empty; | ||
const coerce = v => { | ||
if (Array.isArray(v)) { | ||
return v.filter(it => !empty(it)); | ||
} | ||
return v; | ||
}; // Remove all undefined, null, empty strings, empty object and empty array values | ||
const clean = src => JSON.parse(JSON.stringify(src), (k, v) => empty(v) ? undefined : coerce(v)); | ||
exports.clean = clean; | ||
const coerce = (v) => { | ||
if (Array.isArray(v)) { | ||
return v.filter((it) => !(0, exports.empty)(it)); | ||
} | ||
return v; | ||
}; | ||
// Remove all undefined, null, empty strings, empty object and empty array values | ||
const clean = (src) => JSON.parse(JSON.stringify(src), (k, v) => ((0, exports.empty)(v) ? undefined : coerce(v))); | ||
exports.clean = clean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compose = void 0; | ||
var _pipe = require("./pipe"); | ||
const compose = (...fn) => (0, _pipe.pipe)(...fn.reverse()); | ||
exports.compose = compose; | ||
const pipe_1 = require("./pipe"); | ||
const compose = (...fn) => (0, pipe_1.pipe)(...fn.reverse()); | ||
exports.compose = compose; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.curry = void 0; | ||
const curry = (arity = 0, fn) => (...args) => { | ||
// we have surpassed the expected arity, so invoke the final function | ||
if (arity <= args.length) { | ||
return fn(...args); | ||
} // we still have args we can bind, recurse | ||
const bound = fn.bind(fn, ...args); | ||
return curry(arity - args.length, bound); | ||
// we have surpassed the expected arity, so invoke the final function | ||
if (arity <= args.length) { | ||
return fn(...args); | ||
} | ||
// we still have args we can bind, recurse | ||
const bound = fn.bind(fn, ...args); | ||
return (0, exports.curry)(arity - args.length, bound); | ||
}; | ||
exports.curry = curry; | ||
exports.curry = curry; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dot = void 0; | ||
const LEADING_ARRAY = /\[/g; | ||
const TRAILING_ARRAY = /^\[|\]/g; | ||
const dot = path => path.replace(TRAILING_ARRAY, '').replace(LEADING_ARRAY, '.').split('.'); | ||
exports.dot = dot; | ||
const dot = (path) => path.replace(TRAILING_ARRAY, '').replace(LEADING_ARRAY, '.').split('.'); | ||
exports.dot = dot; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.filter = void 0; | ||
const { | ||
objecToEquality | ||
} = require('./arrays'); | ||
const filter = arg => src => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = objecToEquality(arg); | ||
} | ||
return Array.isArray(src) ? src.filter(fn) : []; | ||
const arrays_1 = require("./arrays"); | ||
const filter = (arg) => (src) => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = (0, arrays_1.objecToEquality)(arg); | ||
} | ||
return Array.isArray(src) ? src.filter(fn) : []; | ||
}; | ||
exports.filter = filter; | ||
exports.filter = filter; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.find = void 0; | ||
const { | ||
objecToEquality | ||
} = require('./arrays'); | ||
const find = arg => src => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = objecToEquality(arg); | ||
} | ||
return Array.isArray(src) ? src.find(fn) : undefined; | ||
const arrays_1 = require("./arrays"); | ||
const find = (arg) => (src) => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = (0, arrays_1.objecToEquality)(arg); | ||
} | ||
return Array.isArray(src) ? src.find(fn) : undefined; | ||
}; | ||
exports.find = find; | ||
exports.find = find; |
225
lib/index.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _parallel = require("./parallel"); | ||
Object.keys(_parallel).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _parallel[key]; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
}); | ||
}); | ||
var _compose = require("./compose"); | ||
Object.keys(_compose).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _compose[key]; | ||
} | ||
}); | ||
}); | ||
var _curry = require("./curry"); | ||
Object.keys(_curry).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _curry[key]; | ||
} | ||
}); | ||
}); | ||
var _map = require("./map"); | ||
Object.keys(_map).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _map[key]; | ||
} | ||
}); | ||
}); | ||
var _filter = require("./filter"); | ||
Object.keys(_filter).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _filter[key]; | ||
} | ||
}); | ||
}); | ||
var _find = require("./find"); | ||
Object.keys(_find).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _find[key]; | ||
} | ||
}); | ||
}); | ||
var _pick = require("./pick"); | ||
Object.keys(_pick).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _pick[key]; | ||
} | ||
}); | ||
}); | ||
var _pipe = require("./pipe"); | ||
Object.keys(_pipe).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _pipe[key]; | ||
} | ||
}); | ||
}); | ||
var _toss = require("./toss"); | ||
Object.keys(_toss).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _toss[key]; | ||
} | ||
}); | ||
}); | ||
var _clean = require("./clean"); | ||
Object.keys(_clean).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _clean[key]; | ||
} | ||
}); | ||
}); | ||
var _nonce = require("./nonce"); | ||
Object.keys(_nonce).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _nonce[key]; | ||
} | ||
}); | ||
}); | ||
var _retry = require("./retry"); | ||
Object.keys(_retry).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _retry[key]; | ||
} | ||
}); | ||
}); | ||
var _settle = require("./settle"); | ||
Object.keys(_settle).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _settle[key]; | ||
} | ||
}); | ||
}); | ||
var _timeout = require("./timeout"); | ||
Object.keys(_timeout).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _timeout[key]; | ||
} | ||
}); | ||
}); | ||
var _noop = require("./noop"); | ||
Object.keys(_noop).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _noop[key]; | ||
} | ||
}); | ||
}); | ||
var _poll = require("./poll"); | ||
Object.keys(_poll).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _poll[key]; | ||
} | ||
}); | ||
}); | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./parallel"), exports); | ||
__exportStar(require("./compose"), exports); | ||
__exportStar(require("./curry"), exports); | ||
__exportStar(require("./map"), exports); | ||
__exportStar(require("./filter"), exports); | ||
__exportStar(require("./find"), exports); | ||
__exportStar(require("./pick"), exports); | ||
__exportStar(require("./pipe"), exports); | ||
__exportStar(require("./toss"), exports); | ||
__exportStar(require("./clean"), exports); | ||
__exportStar(require("./nonce"), exports); | ||
__exportStar(require("./retry"), exports); | ||
__exportStar(require("./settle"), exports); | ||
__exportStar(require("./timeout"), exports); | ||
__exportStar(require("./noop"), exports); | ||
__exportStar(require("./poll"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.map = void 0; | ||
const { | ||
pick | ||
} = require('./pick'); | ||
const map = arg => src => { | ||
let fn = arg; | ||
if (Array.isArray(arg)) { | ||
fn = pick(arg); | ||
} | ||
return Array.isArray(src) ? src.map(fn) : src ? fn(src, 0, src) : undefined; | ||
const pick_1 = require("./pick"); | ||
const map = (arg) => (src) => { | ||
let fn = arg; | ||
if (Array.isArray(arg)) { | ||
fn = (0, pick_1.pick)(arg); | ||
} | ||
return Array.isArray(src) ? src.map(fn) : src ? fn(src, 0) : undefined; | ||
}; | ||
exports.map = map; | ||
exports.map = map; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.once = exports.nonce = void 0; | ||
/* eslint-disable no-plusplus */ | ||
const nonce = (fn, times = 1) => { | ||
let i = 0; | ||
return (...args) => i++ <= times - 1 ? fn(...args) : undefined; | ||
let i = 0; | ||
return (...args) => (i++ <= times - 1 ? fn(...args) : undefined); | ||
}; | ||
exports.nonce = nonce; | ||
const once = fn => nonce(fn); | ||
exports.once = once; | ||
const once = (fn) => (0, exports.nonce)(fn); | ||
exports.once = once; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.noop = void 0; | ||
const noop = () => {}; | ||
exports.noop = noop; | ||
const noop = () => { }; | ||
exports.noop = noop; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parallel = void 0; | ||
const parallel = (...fns) => (...args) => Promise.all(fns.map(fn => fn(...args))); | ||
exports.parallel = parallel; | ||
const parallel = (...fns) => (...args) => Promise.all(fns.map((fn) => fn(...args))); | ||
exports.parallel = parallel; |
108
lib/pick.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pick = exports.get = void 0; | ||
var _dot = require("./dot"); | ||
var _clean = require("./clean"); | ||
const get = (path, def = undefined) => obj => { | ||
try { | ||
return (0, _dot.dot)(path).reduce((a, b) => a[b], obj); | ||
} catch (e) { | ||
return def; | ||
} | ||
const dot_1 = require("./dot"); | ||
const clean_1 = require("./clean"); | ||
const get = (path, def) => (obj) => { | ||
try { | ||
return (0, dot_1.dot)(path).reduce((a, b) => a[b], obj); | ||
} | ||
catch (e) { | ||
return def; | ||
} | ||
}; | ||
exports.get = get; | ||
const pick = (paths, options = {}) => src => { | ||
const output = Array.isArray(src) ? [] : {}; | ||
for (let j = 0; j < paths.length; j++) { | ||
const originalPath = paths[j]; | ||
const path = (0, _dot.dot)(originalPath); | ||
const value = get(originalPath)(src); // don't try to find something that doesn't exist | ||
if (!path[0].match(/\d/g) && !src.hasOwnProperty(path[0])) { | ||
continue; | ||
const pick = (paths, options) => (src) => { | ||
const output = Array.isArray(src) ? [] : {}; | ||
for (let j = 0; j < paths.length; j++) { | ||
const originalPath = paths[j]; | ||
const path = (0, dot_1.dot)(originalPath); | ||
const value = (0, exports.get)(originalPath)(src); | ||
// don't try to find something that doesn't exist | ||
if (!path[0].match(/\d/g) && !src.hasOwnProperty(path[0])) { | ||
continue; | ||
} | ||
let target = output; | ||
for (let i = 0; i < path.length; i++) { | ||
const part = path[i]; | ||
const next = path[i + 1]; | ||
// already defined and not at the end | ||
if (target[part]) { | ||
target = target[part]; | ||
continue; | ||
} | ||
// next part is array | ||
if (next && next.match(/\d/g)) { | ||
target[part] = []; | ||
target = target[part]; | ||
continue; | ||
} | ||
if (next) { | ||
target[part] = {}; | ||
target = target[part]; | ||
} | ||
} | ||
const last = path[path.length - 1]; | ||
target[last] = value; | ||
} | ||
let target = output; | ||
for (let i = 0; i < path.length; i++) { | ||
const part = path[i]; | ||
const next = path[i + 1]; // already defined and not at the end | ||
if (target[part]) { | ||
target = target[part]; | ||
continue; | ||
} // next part is array | ||
if (next && next.match(/\d/g)) { | ||
target[part] = []; | ||
target = target[part]; | ||
continue; | ||
} | ||
if (next) { | ||
target[part] = {}; | ||
target = target[part]; | ||
} | ||
if (options && options.clean) { | ||
return (0, clean_1.clean)(output); | ||
} | ||
const last = path[path.length - 1]; | ||
target[last] = value; | ||
} | ||
if (options.clean) { | ||
return (0, _clean.clean)(output); | ||
} | ||
return output; | ||
return output; | ||
}; | ||
exports.pick = pick; | ||
exports.pick = pick; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pipe = exports.thennable = void 0; | ||
const thennable = v => v && v.then && typeof v.then === 'function' || v && v[Symbol.toStringTag] === 'AsyncFunction'; | ||
const thennable = (v) => (v && v.then && typeof v.then === 'function') || | ||
(v && v[Symbol.toStringTag] === 'AsyncFunction'); | ||
exports.thennable = thennable; | ||
const pipe = (...fn) => initial => fn.reduce((a, n) => thennable(a) ? a.then(n) : n(a), initial); | ||
exports.pipe = pipe; | ||
const pipe = (...fn) => (initial) => fn.reduce((a, n) => ((0, exports.thennable)(a) ? a.then(n) : n(a)), initial); | ||
exports.pipe = pipe; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.poll = void 0; | ||
var _timeout = require("./timeout"); | ||
/* eslint-disable no-await-in-loop */ | ||
/* eslint-disable camelcase */ | ||
const DEFAULT_ROLLOFF = async (ms = 200) => (0, _timeout.sleep)(ms); | ||
const timeout_1 = require("./timeout"); | ||
const DEFAULT_ROLLOFF = (ms = 200) => __awaiter(void 0, void 0, void 0, function* () { return (0, timeout_1.sleep)(ms); }); | ||
const poll = (fn, it) => { | ||
let rolloff; | ||
if (typeof it === 'function') { | ||
rolloff = it; | ||
} else if (typeof it === 'number') { | ||
rolloff = async () => DEFAULT_ROLLOFF(it); | ||
} else { | ||
rolloff = async () => DEFAULT_ROLLOFF(); | ||
} | ||
let is_cancelled = false; | ||
(async () => { | ||
let i = 0; | ||
while (!is_cancelled) { | ||
await fn(); | ||
await rolloff(i += 1); | ||
let rolloff; | ||
if (typeof it === 'function') { | ||
rolloff = it; | ||
} | ||
})(); | ||
return () => { | ||
is_cancelled = true; | ||
}; | ||
else if (typeof it === 'number') { | ||
rolloff = () => __awaiter(void 0, void 0, void 0, function* () { return DEFAULT_ROLLOFF(it); }); | ||
} | ||
else { | ||
rolloff = () => __awaiter(void 0, void 0, void 0, function* () { return DEFAULT_ROLLOFF(); }); | ||
} | ||
let is_cancelled = false; | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
let i = 0; | ||
while (!is_cancelled) { | ||
yield fn(); | ||
yield rolloff((i += 1)); | ||
} | ||
}))(); | ||
return () => { | ||
is_cancelled = true; | ||
}; | ||
}; | ||
exports.poll = poll; | ||
exports.poll = poll; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.retrySync = exports.retry = void 0; | ||
/* eslint-disable no-await-in-loop */ | ||
const DEFAULT_ROLLOFF = async () => {}; | ||
const retry = (fn, max = 3, rolloff = DEFAULT_ROLLOFF) => async (...args) => { | ||
for (let i = 0; i < max; i += 1) { | ||
try { | ||
return await fn(...args); | ||
} catch (e) { | ||
if (i + 1 >= max) { | ||
throw e; | ||
} | ||
await rolloff(i + 1); | ||
const DEFAULT_ROLLOFF = (retryCount) => __awaiter(void 0, void 0, void 0, function* () { }); | ||
const retry = (fn, max = 3, rolloff = DEFAULT_ROLLOFF) => (...args) => __awaiter(void 0, void 0, void 0, function* () { | ||
for (let i = 0; i < max; i += 1) { | ||
try { | ||
return yield fn(...args); | ||
} | ||
catch (e) { | ||
if (i + 1 >= max) { | ||
throw e; | ||
} | ||
yield rolloff(i + 1); | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
exports.retry = retry; | ||
const retrySync = (fn, max = 3) => (...args) => { | ||
for (let i = max - 1; i > -1; i -= 1) { | ||
try { | ||
return fn(...args); | ||
} catch (e) { | ||
if (!i) { | ||
throw e; | ||
} | ||
for (let i = max - 1; i > -1; i -= 1) { | ||
try { | ||
return fn(...args); | ||
} | ||
catch (e) { | ||
if (!i) { | ||
throw e; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
exports.retrySync = retrySync; | ||
exports.retrySync = retrySync; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.settle = void 0; | ||
/* eslint-disable no-nested-ternary */ | ||
const thennable = v => v && v.then && typeof v.then === 'function' || v && v[Symbol.toStringTag] === 'AsyncFunction'; | ||
const settleOne = it => thennable(it) ? it.then(x => ({ | ||
success: true, | ||
value: x | ||
}), e => ({ | ||
success: false, | ||
reason: e | ||
})) : typeof it === 'function' ? it() : it; | ||
const settle = it => typeof it === 'function' ? async (...args) => settleOne(it(...args)) : Promise.all(it.map(settleOne)); | ||
exports.settle = settle; | ||
const thennable = (v) => (v && v.then && typeof v.then === 'function') || | ||
(v && v[Symbol.toStringTag] === 'AsyncFunction'); | ||
const settleOne = (it) => thennable(it) | ||
? it.then((x) => ({ success: true, value: x }), (e) => ({ success: false, reason: e })) | ||
: typeof it === 'function' | ||
? it() | ||
: it; | ||
const settle = (it) => typeof it === 'function' | ||
? (...args) => __awaiter(void 0, void 0, void 0, function* () { return settleOne(it(...args)); }) | ||
: Promise.all(it.map(settleOne)); | ||
exports.settle = settle; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.some = void 0; | ||
const { | ||
objecToEquality | ||
} = require('./arrays'); | ||
const some = arg => src => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = objecToEquality(arg); | ||
} | ||
return Array.isArray(src) ? src.some(fn) : false; | ||
const arrays_1 = require("./arrays"); | ||
const some = (arg) => (src) => { | ||
let fn = arg; | ||
if (typeof fn !== 'function') { | ||
fn = (0, arrays_1.objecToEquality)(arg); | ||
} | ||
return Array.isArray(src) ? src.some(fn) : false; | ||
}; | ||
exports.some = some; | ||
exports.some = some; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.timeout = exports.race = exports.sleep = void 0; | ||
const sleep = (millis, ...params) => new Promise(resolve => setTimeout(resolve, millis, ...params)); // Create an alias for Promise.race | ||
const sleep = (millis, ...params) => new Promise((resolve) => setTimeout(resolve, millis, ...params)); | ||
exports.sleep = sleep; | ||
const { | ||
race | ||
} = Promise; | ||
exports.race = race; | ||
const timeout = (fn, millis = 500) => (...args) => Promise.race([sleep(millis, 'timeout'), fn(...args)]).then(result => { | ||
if (result === 'timeout') { | ||
throw new Error(`Function ${fn.name || 'Anonymous'} timed out`); | ||
} | ||
return result; | ||
// Create an alias for Promise.race | ||
exports.race = Promise.race; | ||
const timeout = (fn, millis = 500) => (...args) => Promise.race([(0, exports.sleep)(millis, 'timeout'), fn(...args)]).then((result) => { | ||
if (result === 'timeout') { | ||
throw new Error(`Function ${fn.name || 'Anonymous'} timed out`); | ||
} | ||
return result; | ||
}); | ||
exports.timeout = timeout; | ||
exports.timeout = timeout; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toss = void 0; | ||
const toss = msg => (properties = {}) => { | ||
const e = new Error(msg || 'An unknown error occured'); | ||
Object.assign(e, properties); | ||
throw e; | ||
const toss = (msg) => (properties = {}) => { | ||
const e = new Error(msg || 'An unknown error occured'); | ||
Object.assign(e, properties); | ||
throw e; | ||
}; | ||
exports.toss = toss; | ||
exports.toss = toss; |
{ | ||
"name": "@teleology/fp", | ||
"version": "2.0.3", | ||
"version": "3.0.1", | ||
"description": "A small collection of functional programming utils", | ||
@@ -23,12 +23,5 @@ "author": "Chris Sullivan <chrissullivan.dev@gmail.com>", | ||
"test:coverage": "yarn test --coverage", | ||
"prepare": "npx babel src --out-dir lib" | ||
"prepare": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.6.4", | ||
"@babel/core": "^7.6.2", | ||
"@babel/polyfill": "^7.6.0", | ||
"@babel/preset-env": "^7.6.2", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0", | ||
"babel-loader": "^8.0.6", | ||
"eslint": "^7.6.0", | ||
@@ -41,4 +34,5 @@ "eslint-config-airbnb-base": "^14.2.0", | ||
"jest": "^26.2.2", | ||
"prettier": "^2.0.5" | ||
"prettier": "^2.0.5", | ||
"typescript": "^4.6.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26375
9
45
421
1