@webshrine/stdlib
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,6 +0,2 @@ | ||
import { CompareResultValue, FnCompare } from '@webshrine/stdtyp'; | ||
/** | ||
* | ||
*/ | ||
export declare const invertComparator: <T>(compareFn: FnCompare<T>) => FnCompare<T>; | ||
import { CompareResultValue } from '@webshrine/stdtyp'; | ||
export declare const enum CompareResult { | ||
@@ -7,0 +3,0 @@ EQUAL = 0, |
@@ -10,4 +10,2 @@ import { AnyArray, AnyObject, Collection, Falsy, Fn, FnGuard, Nullish, Numeric, Primitive } from '@webshrine/stdtyp'; | ||
export declare const isPrimitive: FnGuard<Primitive>; | ||
export declare const isError: FnGuard<Error>; | ||
export declare const isNative: FnGuard<Fn>; | ||
export declare const isObject: FnGuard<AnyObject>; | ||
@@ -14,0 +12,0 @@ export declare const isPlainObject: FnGuard<AnyObject>; |
@@ -1,2 +0,110 @@ | ||
const invertComparator = (compareFn) => (a, b) => compareFn(b, a); | ||
const DEBOUNCE_DEFAULTS = { | ||
trailing: true | ||
}; | ||
function debounce$1(fn, wait = 25, options = {}) { | ||
options = { ...DEBOUNCE_DEFAULTS, ...options }; | ||
if (!Number.isFinite(wait)) { | ||
throw new TypeError("Expected `wait` to be a finite number"); | ||
} | ||
let leadingValue; | ||
let timeout; | ||
let resolveList = []; | ||
let currentPromise; | ||
let trailingArgs; | ||
const applyFn = (_this, args) => { | ||
currentPromise = _applyPromised(fn, _this, args); | ||
currentPromise.finally(() => { | ||
currentPromise = null; | ||
if (options.trailing && trailingArgs && !timeout) { | ||
const promise = applyFn(_this, trailingArgs); | ||
trailingArgs = null; | ||
return promise; | ||
} | ||
}); | ||
return currentPromise; | ||
}; | ||
return function(...args) { | ||
if (currentPromise) { | ||
if (options.trailing) { | ||
trailingArgs = args; | ||
} | ||
return currentPromise; | ||
} | ||
return new Promise((resolve) => { | ||
const shouldCallNow = !timeout && options.leading; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(() => { | ||
timeout = null; | ||
const promise = options.leading ? leadingValue : applyFn(this, args); | ||
for (const _resolve of resolveList) { | ||
_resolve(promise); | ||
} | ||
resolveList = []; | ||
}, wait); | ||
if (shouldCallNow) { | ||
leadingValue = applyFn(this, args); | ||
resolve(leadingValue); | ||
} else { | ||
resolveList.push(resolve); | ||
} | ||
}); | ||
}; | ||
} | ||
async function _applyPromised(fn, _this, args) { | ||
return await fn.apply(_this, args); | ||
} | ||
function getDefaultExportFromCjs(x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; | ||
} | ||
var throttleit$1; | ||
var hasRequiredThrottleit; | ||
function requireThrottleit() { | ||
if (hasRequiredThrottleit) return throttleit$1; | ||
hasRequiredThrottleit = 1; | ||
function throttle2(function_, wait) { | ||
if (typeof function_ !== "function") { | ||
throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof function_}\`.`); | ||
} | ||
let timeoutId; | ||
let lastCallTime = 0; | ||
return function throttled(...arguments_) { | ||
clearTimeout(timeoutId); | ||
const now = Date.now(); | ||
const timeSinceLastCall = now - lastCallTime; | ||
const delayForNextCall = wait - timeSinceLastCall; | ||
if (delayForNextCall <= 0) { | ||
lastCallTime = now; | ||
function_.apply(this, arguments_); | ||
} else { | ||
timeoutId = setTimeout(() => { | ||
lastCallTime = Date.now(); | ||
function_.apply(this, arguments_); | ||
}, delayForNextCall); | ||
} | ||
}; | ||
} | ||
throttleit$1 = throttle2; | ||
return throttleit$1; | ||
} | ||
var throttleitExports = /* @__PURE__ */ requireThrottleit(); | ||
const throttleit = /* @__PURE__ */ getDefaultExportFromCjs(throttleitExports); | ||
const debounce = debounce$1; | ||
const throttle = throttleit; | ||
const once = (fn) => { | ||
let wasCalled = false; | ||
let result; | ||
return (...args) => { | ||
if (wasCalled) | ||
return result; | ||
wasCalled = true; | ||
return result = fn(...args); | ||
}; | ||
}; | ||
const negate = (fn) => { | ||
return (...args) => { | ||
const result = fn(...args); | ||
return typeof result === "boolean" ? !result : result.then((r) => !r); | ||
}; | ||
}; | ||
const invert = (compareFn) => (a, b) => compareFn(b, a); | ||
var CompareResult = /* @__PURE__ */ ((CompareResult2) => { | ||
@@ -19,7 +127,7 @@ CompareResult2[CompareResult2["EQUAL"] = 0] = "EQUAL"; | ||
const compareDate = (a, b) => compareNumber(a.getTime(), b.getTime()); | ||
const compareNumberReverse = invertComparator(compareNumber); | ||
const compareNumberAbsReverse = invertComparator(compareNumberAbs); | ||
const compareArrayLengthReverse = invertComparator(compareArrayLength); | ||
const compareStringReverse = invertComparator(compareString); | ||
const compareDateReverse = invertComparator(compareDate); | ||
const compareNumberReverse = invert(compareNumber); | ||
const compareNumberAbsReverse = invert(compareNumberAbs); | ||
const compareArrayLengthReverse = invert(compareArrayLength); | ||
const compareStringReverse = invert(compareString); | ||
const compareDateReverse = invert(compareDate); | ||
var freeGlobal = typeof global == "object" && global && global.Object === Object && global; | ||
@@ -29,8 +137,8 @@ var freeSelf = typeof self == "object" && self && self.Object === Object && self; | ||
var Symbol$1 = root.Symbol; | ||
var objectProto$3 = Object.prototype; | ||
var hasOwnProperty$2 = objectProto$3.hasOwnProperty; | ||
var nativeObjectToString$1 = objectProto$3.toString; | ||
var objectProto$1 = Object.prototype; | ||
var hasOwnProperty = objectProto$1.hasOwnProperty; | ||
var nativeObjectToString$1 = objectProto$1.toString; | ||
var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : void 0; | ||
function getRawTag(value) { | ||
var isOwn = hasOwnProperty$2.call(value, symToStringTag$1), tag = value[symToStringTag$1]; | ||
var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1]; | ||
try { | ||
@@ -51,4 +159,4 @@ value[symToStringTag$1] = void 0; | ||
} | ||
var objectProto$2 = Object.prototype; | ||
var nativeObjectToString = objectProto$2.toString; | ||
var objectProto = Object.prototype; | ||
var nativeObjectToString = objectProto.toString; | ||
function objectToString(value) { | ||
@@ -68,6 +176,2 @@ return nativeObjectToString.call(value); | ||
} | ||
var symbolTag = "[object Symbol]"; | ||
function isSymbol$1(value) { | ||
return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag; | ||
} | ||
function isObject$1(value) { | ||
@@ -85,48 +189,5 @@ var type = typeof value; | ||
} | ||
var coreJsData = root["__core-js_shared__"]; | ||
var maskSrcKey = function() { | ||
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ""); | ||
return uid ? "Symbol(src)_1." + uid : ""; | ||
}(); | ||
function isMasked(func) { | ||
return !!maskSrcKey && maskSrcKey in func; | ||
} | ||
var funcProto$2 = Function.prototype; | ||
var funcToString$2 = funcProto$2.toString; | ||
function toSource(func) { | ||
if (func != null) { | ||
try { | ||
return funcToString$2.call(func); | ||
} catch (e) { | ||
} | ||
try { | ||
return func + ""; | ||
} catch (e) { | ||
} | ||
} | ||
return ""; | ||
} | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
var funcProto$1 = Function.prototype, objectProto$1 = Object.prototype; | ||
var funcToString$1 = funcProto$1.toString; | ||
var hasOwnProperty$1 = objectProto$1.hasOwnProperty; | ||
var reIsNative = RegExp( | ||
"^" + funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$" | ||
); | ||
function baseIsNative(value) { | ||
if (!isObject$1(value) || isMasked(value)) { | ||
return false; | ||
} | ||
var pattern = isFunction$1(value) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
} | ||
function noop() { | ||
} | ||
function eq(value, other) { | ||
return value === other || value !== value && other !== other; | ||
} | ||
function stubFalse() { | ||
return false; | ||
} | ||
function baseUnary(func) { | ||
@@ -151,36 +212,2 @@ return function(value) { | ||
}(); | ||
function overArg(func, transform) { | ||
return function(arg) { | ||
return func(transform(arg)); | ||
}; | ||
} | ||
var getPrototype = overArg(Object.getPrototypeOf, Object); | ||
var objectTag = "[object Object]"; | ||
var funcProto = Function.prototype, objectProto = Object.prototype; | ||
var funcToString = funcProto.toString; | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
var objectCtorString = funcToString.call(Object); | ||
function isPlainObject$1(value) { | ||
if (!isObjectLike(value) || baseGetTag(value) != objectTag) { | ||
return false; | ||
} | ||
var proto = getPrototype(value); | ||
if (proto === null) { | ||
return true; | ||
} | ||
var Ctor = hasOwnProperty.call(proto, "constructor") && proto.constructor; | ||
return typeof Ctor == "function" && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString; | ||
} | ||
var domExcTag = "[object DOMException]", errorTag = "[object Error]"; | ||
function isError$1(value) { | ||
if (!isObjectLike(value)) { | ||
return false; | ||
} | ||
var tag = baseGetTag(value); | ||
return tag == errorTag || tag == domExcTag || typeof value.message == "string" && typeof value.name == "string" && !isPlainObject$1(value); | ||
} | ||
var boolTag = "[object Boolean]"; | ||
function isBoolean$1(value) { | ||
return value === true || value === false || isObjectLike(value) && baseGetTag(value) == boolTag; | ||
} | ||
var dateTag = "[object Date]"; | ||
@@ -192,13 +219,2 @@ function baseIsDate(value) { | ||
var isDate$1 = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; | ||
var isMaskable = coreJsData ? isFunction$1 : stubFalse; | ||
var CORE_ERROR_TEXT = "Unsupported core-js use. Try https://npms.io/search?q=ponyfill."; | ||
function isNative$1(value) { | ||
if (isMaskable(value)) { | ||
throw new Error(CORE_ERROR_TEXT); | ||
} | ||
return baseIsNative(value); | ||
} | ||
function getDefaultExportFromCjs(x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; | ||
} | ||
var dist = {}; | ||
@@ -266,15 +282,26 @@ var aliasesAndGuards = {}; | ||
var distExports = requireDist(); | ||
function isPlainObject$2(value) { | ||
if (value === null || typeof value !== "object") | ||
return false; | ||
const prototype = Object.getPrototypeOf(value); | ||
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) { | ||
return false; | ||
} | ||
if (Symbol.iterator in value) | ||
return false; | ||
if (Symbol.toStringTag in value) | ||
return Object.prototype.toString.call(value) === "[object Module]"; | ||
return true; | ||
} | ||
const isArray = Array.isArray; | ||
const isBoolean = isBoolean$1; | ||
const isBoolean = (n) => typeof n === "boolean"; | ||
const isDate = isDate$1; | ||
const isFunction = isFunction$1; | ||
const isSymbol = isSymbol$1; | ||
const isSymbol = (n) => typeof n === "symbol"; | ||
const isFalsy = distExports.isFalsy; | ||
const isNullish = distExports.isNullish; | ||
const isPrimitive = distExports.isPrimitive; | ||
const isError = isError$1; | ||
const isNative = isNative$1; | ||
const isObject = isObject$1; | ||
const isPlainObject = isPlainObject$1; | ||
const isCollection = (v) => isArray(v) || isPlainObject(v); | ||
const isPlainObject$1 = isPlainObject$2; | ||
const isCollection = (v) => isArray(v) || isPlainObject$1(v); | ||
const isNumber = (n) => typeof n === "number"; | ||
@@ -498,13 +525,17 @@ const isNumberOdd = (n) => n % 2 === 1; | ||
} | ||
const noop = () => { | ||
}; | ||
const through = (arg) => arg; | ||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
const forEachItem = (array, cb) => { | ||
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key); | ||
const forItems = (array, cb) => { | ||
for (let index = 0, max = array.length; index < max; index++) | ||
cb(array[index], index, array); | ||
}; | ||
const forEachValue = (object, cb) => { | ||
for (const key in object) | ||
const forValues = (object, cb) => { | ||
for (const key of Object.keys(object)) | ||
cb(object[key], key, object); | ||
}; | ||
const forEachSymbol = (object, cb) => { | ||
forEachItem( | ||
const forSymbols = (object, cb) => { | ||
forItems( | ||
symbols(object), | ||
@@ -515,3 +546,3 @@ (symbol) => cb(object[symbol], symbol, object) | ||
const forEach = (collection, cb) => { | ||
Array.isArray(collection) ? forEachItem(collection, cb) : forEachValue(collection, cb); | ||
Array.isArray(collection) ? forItems(collection, cb) : forValues(collection, cb); | ||
}; | ||
@@ -530,5 +561,28 @@ function forEachDeepIterate(callback, node, level) { | ||
} | ||
const mapItems = (array, cb) => { | ||
const result = []; | ||
for (let index = 0, max = array.length; index < max; index++) | ||
result[index] = cb(array[index], index, array); | ||
return result; | ||
}; | ||
const mapValues = (object, cb) => { | ||
const result = {}; | ||
for (const key of Object.keys(object)) | ||
result[key] = cb(object[key], key, object); | ||
return result; | ||
}; | ||
const map = (collection, cb) => Array.isArray(collection) ? mapItems(collection, cb) : mapValues(collection, cb); | ||
function times(count, callback) { | ||
for (let index = 0; index < count; index++) | ||
callback(index + 1, index, count); | ||
} | ||
function timesMap(count, callback) { | ||
const result = []; | ||
for (let index = 0; index < count; index++) | ||
result[index] = callback(index + 1, index, count); | ||
return result; | ||
} | ||
const keys = (object) => Object.keys(object); | ||
const indexExtractor = (_, index) => index; | ||
const indexes = (array) => Array.from(array).map(indexExtractor); | ||
const indexes = (array) => timesMap(array.length, indexExtractor); | ||
const symbols = (object) => Object.getOwnPropertySymbols(object); | ||
@@ -546,2 +600,56 @@ const values = (object) => Object.values(object); | ||
const collectionKeys = (collection) => Array.isArray(collection) ? indexes(collection) : keys(collection); | ||
function isPlainObject(value) { | ||
if (value === null || typeof value !== "object") { | ||
return false; | ||
} | ||
const prototype = Object.getPrototypeOf(value); | ||
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) { | ||
return false; | ||
} | ||
if (Symbol.iterator in value) { | ||
return false; | ||
} | ||
if (Symbol.toStringTag in value) { | ||
return Object.prototype.toString.call(value) === "[object Module]"; | ||
} | ||
return true; | ||
} | ||
function _defu(baseObject, defaults, namespace = ".", merger) { | ||
if (!isPlainObject(defaults)) { | ||
return _defu(baseObject, {}, namespace, merger); | ||
} | ||
const object = Object.assign({}, defaults); | ||
for (const key in baseObject) { | ||
if (key === "__proto__" || key === "constructor") { | ||
continue; | ||
} | ||
const value = baseObject[key]; | ||
if (value === null || value === void 0) { | ||
continue; | ||
} | ||
if (merger && merger(object, key, value, namespace)) { | ||
continue; | ||
} | ||
if (Array.isArray(value) && Array.isArray(object[key])) { | ||
object[key] = [...value, ...object[key]]; | ||
} else if (isPlainObject(value) && isPlainObject(object[key])) { | ||
object[key] = _defu( | ||
value, | ||
object[key], | ||
(namespace ? `${namespace}.` : "") + key.toString(), | ||
merger | ||
); | ||
} else { | ||
object[key] = value; | ||
} | ||
} | ||
return object; | ||
} | ||
function createDefu(merger) { | ||
return (...arguments_) => ( | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
arguments_.reduce((p, c) => _defu(p, c, "", merger), {}) | ||
); | ||
} | ||
const defu = createDefu(); | ||
const createDeepObjectTransformer = (transformer) => { | ||
@@ -593,3 +701,3 @@ return function transform(collection, parameter) { | ||
for (const key of keys2) { | ||
if (Object.prototype.hasOwnProperty.call(object, key)) | ||
if (hasOwn(object, key)) | ||
result[key] = object[key]; | ||
@@ -611,3 +719,2 @@ } | ||
}, []); | ||
const uniqueItems = (array) => [...new Set(array)]; | ||
const uniqueValuesBy = (object, matcher) => Object.entries(object).reduce((acc, [key, value], _index, entries) => { | ||
@@ -619,136 +726,6 @@ const exists = entries.some((pair) => matcher(pair[1], value)); | ||
}, {}); | ||
const uniqueItems = (array) => [...new Set(array)]; | ||
const uniqueValues = (object) => uniqueValuesBy(object, areSame); | ||
const unique = (collection) => Array.isArray(collection) ? uniqueItems(collection) : uniqueValues(collection); | ||
const uniqueBy = (collection, matcher) => Array.isArray(collection) ? uniqueItemsBy(collection, matcher) : uniqueValuesBy(collection, matcher); | ||
var debounce$1 = { exports: {} }; | ||
var hasRequiredDebounce; | ||
function requireDebounce() { | ||
if (hasRequiredDebounce) return debounce$1.exports; | ||
hasRequiredDebounce = 1; | ||
function debounce2(function_, wait = 100, options = {}) { | ||
if (typeof function_ !== "function") { | ||
throw new TypeError(`Expected the first parameter to be a function, got \`${typeof function_}\`.`); | ||
} | ||
if (wait < 0) { | ||
throw new RangeError("`wait` must not be negative."); | ||
} | ||
const { immediate } = typeof options === "boolean" ? { immediate: options } : options; | ||
let storedContext; | ||
let storedArguments; | ||
let timeoutId; | ||
let timestamp; | ||
let result; | ||
function run() { | ||
const callContext = storedContext; | ||
const callArguments = storedArguments; | ||
storedContext = void 0; | ||
storedArguments = void 0; | ||
result = function_.apply(callContext, callArguments); | ||
return result; | ||
} | ||
function later() { | ||
const last = Date.now() - timestamp; | ||
if (last < wait && last >= 0) { | ||
timeoutId = setTimeout(later, wait - last); | ||
} else { | ||
timeoutId = void 0; | ||
if (!immediate) { | ||
result = run(); | ||
} | ||
} | ||
} | ||
const debounced = function(...arguments_) { | ||
if (storedContext && this !== storedContext && Object.getPrototypeOf(this) === Object.getPrototypeOf(storedContext)) { | ||
throw new Error("Debounced method called with different contexts of the same prototype."); | ||
} | ||
storedContext = this; | ||
storedArguments = arguments_; | ||
timestamp = Date.now(); | ||
const callNow = immediate && !timeoutId; | ||
if (!timeoutId) { | ||
timeoutId = setTimeout(later, wait); | ||
} | ||
if (callNow) { | ||
result = run(); | ||
} | ||
return result; | ||
}; | ||
Object.defineProperty(debounced, "isPending", { | ||
get() { | ||
return timeoutId !== void 0; | ||
} | ||
}); | ||
debounced.clear = () => { | ||
if (!timeoutId) { | ||
return; | ||
} | ||
clearTimeout(timeoutId); | ||
timeoutId = void 0; | ||
}; | ||
debounced.flush = () => { | ||
if (!timeoutId) { | ||
return; | ||
} | ||
debounced.trigger(); | ||
}; | ||
debounced.trigger = () => { | ||
result = run(); | ||
debounced.clear(); | ||
}; | ||
return debounced; | ||
} | ||
debounce$1.exports.debounce = debounce2; | ||
debounce$1.exports = debounce2; | ||
return debounce$1.exports; | ||
} | ||
var debounceExports = /* @__PURE__ */ requireDebounce(); | ||
const _debounce = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports); | ||
var throttleit$1; | ||
var hasRequiredThrottleit; | ||
function requireThrottleit() { | ||
if (hasRequiredThrottleit) return throttleit$1; | ||
hasRequiredThrottleit = 1; | ||
function throttle2(function_, wait) { | ||
if (typeof function_ !== "function") { | ||
throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof function_}\`.`); | ||
} | ||
let timeoutId; | ||
let lastCallTime = 0; | ||
return function throttled(...arguments_) { | ||
clearTimeout(timeoutId); | ||
const now = Date.now(); | ||
const timeSinceLastCall = now - lastCallTime; | ||
const delayForNextCall = wait - timeSinceLastCall; | ||
if (delayForNextCall <= 0) { | ||
lastCallTime = now; | ||
function_.apply(this, arguments_); | ||
} else { | ||
timeoutId = setTimeout(() => { | ||
lastCallTime = Date.now(); | ||
function_.apply(this, arguments_); | ||
}, delayForNextCall); | ||
} | ||
}; | ||
} | ||
throttleit$1 = throttle2; | ||
return throttleit$1; | ||
} | ||
var throttleitExports = /* @__PURE__ */ requireThrottleit(); | ||
const throttleit = /* @__PURE__ */ getDefaultExportFromCjs(throttleitExports); | ||
const debounce = _debounce; | ||
const throttle = throttleit; | ||
const once = (fn) => { | ||
let wasCalled = false; | ||
let result; | ||
return (...args) => { | ||
if (!wasCalled) { | ||
wasCalled = true; | ||
result = fn(...args); | ||
} | ||
return result; | ||
}; | ||
}; | ||
const negate = (fn) => { | ||
return (...args) => !fn(...args); | ||
}; | ||
export { | ||
@@ -778,7 +755,8 @@ CompareResult, | ||
forEachDeep, | ||
forEachItem, | ||
forEachSymbol, | ||
forEachValue, | ||
forItems, | ||
forSymbols, | ||
forValues, | ||
hasOwn, | ||
indexes, | ||
invertComparator, | ||
invert, | ||
isArray, | ||
@@ -794,6 +772,4 @@ isBigInt, | ||
isDate, | ||
isError, | ||
isFalsy, | ||
isFunction, | ||
isNative, | ||
isNullish, | ||
@@ -818,3 +794,3 @@ isNumber, | ||
isObject, | ||
isPlainObject, | ||
isPlainObject$1 as isPlainObject, | ||
isPrimitive, | ||
@@ -839,2 +815,6 @@ isString, | ||
keysDeep, | ||
map, | ||
mapItems, | ||
mapValues, | ||
defu as merge, | ||
negate, | ||
@@ -868,2 +848,5 @@ noop, | ||
throttle, | ||
through, | ||
times, | ||
timesMap, | ||
toCompareResult, | ||
@@ -870,0 +853,0 @@ unique, |
export * from './common'; | ||
export * from './mergers'; | ||
export * from './omitters'; | ||
export * from './pickers'; | ||
export * from './unique'; |
import { AnyArray, AnyObject, Collection, FnMatch } from '@webshrine/stdtyp'; | ||
/** | ||
* | ||
* Returns a new array with only the unique items, uniqueness is determined by received `matcher` function. | ||
*/ | ||
export declare const uniqueItemsBy: <T extends AnyArray>(array: T, matcher: FnMatch<T[number]>) => T; | ||
/** | ||
* | ||
* Returns a new array with only the unique items, uniqueness is determined by received `matcher` function. | ||
*/ | ||
export declare const uniqueItems: <T extends AnyArray>(array: T) => T; | ||
export declare const uniqueValuesBy: <T extends AnyObject>(object: T, matcher: FnMatch<T[keyof T]>) => Partial<T>; | ||
/** | ||
* | ||
* Returns a new array with only the unique items. | ||
*/ | ||
export declare const uniqueValuesBy: <T extends AnyObject>(object: T, matcher: FnMatch<T[keyof T]>) => Partial<T>; | ||
export declare const uniqueItems: <T extends AnyArray>(array: T) => T; | ||
/** | ||
* | ||
* Returns a new object with only the unique values. | ||
*/ | ||
export declare const uniqueValues: <T extends AnyObject>(object: T) => Partial<T>; | ||
/** | ||
* | ||
* Returns a new collection with only the unique items/values. | ||
*/ | ||
export declare const unique: (collection: Collection) => any[] | Partial<Record<import('@webshrine/stdtyp').CollectionKey, any>>; | ||
/** | ||
* | ||
* Returns a new collection with only the unique items/values, but using a custom matcher function. | ||
*/ | ||
export declare const uniqueBy: <T extends Collection>(collection: T, matcher: FnMatch<T[number] | T[keyof T]>) => Partial<T>; |
@@ -0,6 +1,29 @@ | ||
import { AnyObject, FnPredicate } from '@webshrine/stdtyp'; | ||
export * from 'cope'; | ||
export { noop } from 'lodash-es'; | ||
/** | ||
* A no-operation function that returns undefined regardless of the arguments it receives. | ||
* | ||
* Uses as mock in rare cases to satisfy types and decrease the amount of code. | ||
*/ | ||
export declare const noop: () => void; | ||
/** | ||
* A no-operation function that returns the argument it received. | ||
* | ||
* Uses as mock in rare cases to satisfy types and decrease the amount of code. | ||
* @example | ||
* ```ts | ||
* const order: FnWrapper = isDesc ? inverse : through | ||
* const sorter = order(compareNumber) | ||
* | ||
* [1,3,2].sort(sorter) | ||
* ``` | ||
*/ | ||
export declare const through: <T>(arg: T) => T; | ||
/** | ||
* | ||
*/ | ||
export declare const sleep: (ms: number) => Promise<unknown>; | ||
/** | ||
* Checks if the object has own property with the specified key. | ||
*/ | ||
export declare const hasOwn: FnPredicate<[object: AnyObject, key: string]>; |
export * from './clone'; | ||
export * from './common'; | ||
export * from './forEach'; | ||
export * from './loops'; |
@@ -1,6 +0,6 @@ | ||
import { Fn, FnPredicate } from '@webshrine/stdtyp'; | ||
import { default as _debounce } from 'debounce'; | ||
import { Fn, FnAsyncPredicate, FnCompare, FnPredicate } from '@webshrine/stdtyp'; | ||
import { debounce as perfectDebounce } from 'perfect-debounce'; | ||
import { default as throttleit } from 'throttleit'; | ||
export {} from 'lodash-es'; | ||
export declare const debounce: typeof _debounce; | ||
export declare const debounce: typeof perfectDebounce; | ||
export declare const throttle: typeof throttleit; | ||
@@ -14,2 +14,3 @@ /** | ||
* Creates a function that negates the result of the predicate `fn`. | ||
* - Supports async predicates. | ||
* @example | ||
@@ -25,2 +26,12 @@ * | ||
*/ | ||
export declare const negate: <T extends FnPredicate>(fn: T) => T; | ||
export declare const negate: <T extends FnPredicate | FnAsyncPredicate>(fn: T) => T; | ||
/** | ||
* Creates a function that inverts comparison result of received comparing function. | ||
* @example | ||
* const ascending = compareNumber | ||
* const descending = invert(ascending) | ||
* | ||
* [3, 1, 2].sort(ascending) // [1, 2, 3] | ||
* [3, 1, 2].sort(descending) // [3, 2, 1] | ||
*/ | ||
export declare const invert: <T>(compareFn: FnCompare<T>) => FnCompare<T>; |
{ | ||
"name": "@webshrine/stdlib", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"private": false, | ||
@@ -43,6 +43,7 @@ "repository": { | ||
"cope": "^1.0.9", | ||
"debounce": "^2.2.0", | ||
"defu": "^6.1.4", | ||
"fast-deep-equal": "^3.1.3", | ||
"klona": "^2.0.6", | ||
"lodash-es": "^4.17.21", | ||
"perfect-debounce": "^1.0.0", | ||
"throttleit": "^2.1.0", | ||
@@ -52,9 +53,9 @@ "utility-types": "^3.11.0" | ||
"devDependencies": { | ||
"@types/node": "^22.10.1", | ||
"@types/node": "^22.10.2", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
"terser": "^5.36.0", | ||
"vite": "^6.0.1", | ||
"terser": "^5.37.0", | ||
"vite": "^6.0.3", | ||
"vite-plugin-dts": "^4.3.0", | ||
"vitest": "^2.1.6" | ||
"vitest": "^2.1.8" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
3426168
33
12741
10
1
+ Addeddefu@^6.1.4
+ Addedperfect-debounce@^1.0.0
+ Addeddefu@6.1.4(transitive)
+ Addedperfect-debounce@1.0.0(transitive)
- Removeddebounce@^2.2.0
- Removeddebounce@2.2.0(transitive)