@webshrine/stdlib
Advanced tools
Comparing version 0.0.0-alpha.4 to 0.0.0-alpha.5
@@ -199,43 +199,62 @@ const invertComparator = (compareFn) => (a, b) => compareFn(b, a); | ||
var aliasesAndGuards = {}; | ||
Object.defineProperty(aliasesAndGuards, "__esModule", { value: true }); | ||
aliasesAndGuards.isPrimitive = function(val) { | ||
if (val === null || val === void 0) { | ||
return true; | ||
} | ||
switch (typeof val) { | ||
case "string": | ||
case "number": | ||
case "bigint": | ||
case "boolean": | ||
case "symbol": { | ||
var hasRequiredAliasesAndGuards; | ||
function requireAliasesAndGuards() { | ||
if (hasRequiredAliasesAndGuards) return aliasesAndGuards; | ||
hasRequiredAliasesAndGuards = 1; | ||
Object.defineProperty(aliasesAndGuards, "__esModule", { value: true }); | ||
aliasesAndGuards.isPrimitive = function(val) { | ||
if (val === null || val === void 0) { | ||
return true; | ||
} | ||
default: | ||
return false; | ||
switch (typeof val) { | ||
case "string": | ||
case "number": | ||
case "bigint": | ||
case "boolean": | ||
case "symbol": { | ||
return true; | ||
} | ||
default: | ||
return false; | ||
} | ||
}; | ||
aliasesAndGuards.isFalsy = function(val) { | ||
return !val; | ||
}; | ||
aliasesAndGuards.isNullish = function(val) { | ||
return val == null; | ||
}; | ||
return aliasesAndGuards; | ||
} | ||
var functionalHelpers = {}; | ||
var hasRequiredFunctionalHelpers; | ||
function requireFunctionalHelpers() { | ||
if (hasRequiredFunctionalHelpers) return functionalHelpers; | ||
hasRequiredFunctionalHelpers = 1; | ||
Object.defineProperty(functionalHelpers, "__esModule", { value: true }); | ||
function getReturnOfExpression(expression) { | ||
return void 0; | ||
} | ||
}; | ||
aliasesAndGuards.isFalsy = function(val) { | ||
return !val; | ||
}; | ||
aliasesAndGuards.isNullish = function(val) { | ||
return val == null; | ||
}; | ||
var functionalHelpers = {}; | ||
Object.defineProperty(functionalHelpers, "__esModule", { value: true }); | ||
function getReturnOfExpression(expression) { | ||
return void 0; | ||
functionalHelpers.getReturnOfExpression = getReturnOfExpression; | ||
return functionalHelpers; | ||
} | ||
functionalHelpers.getReturnOfExpression = getReturnOfExpression; | ||
/** | ||
* @author Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io) | ||
* @copyright Copyright (c) 2016 Piotr Witek | ||
* @license MIT | ||
*/ | ||
Object.defineProperty(dist, "__esModule", { value: true }); | ||
var aliases_and_guards_1 = aliasesAndGuards; | ||
var isFalsy$1 = dist.isFalsy = aliases_and_guards_1.isFalsy; | ||
var isNullish$1 = dist.isNullish = aliases_and_guards_1.isNullish; | ||
var isPrimitive$1 = dist.isPrimitive = aliases_and_guards_1.isPrimitive; | ||
var functional_helpers_1 = functionalHelpers; | ||
dist.getReturnOfExpression = functional_helpers_1.getReturnOfExpression; | ||
var hasRequiredDist; | ||
function requireDist() { | ||
if (hasRequiredDist) return dist; | ||
hasRequiredDist = 1; | ||
/** | ||
* @author Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io) | ||
* @copyright Copyright (c) 2016 Piotr Witek | ||
* @license MIT | ||
*/ | ||
Object.defineProperty(dist, "__esModule", { value: true }); | ||
var aliases_and_guards_1 = requireAliasesAndGuards(); | ||
dist.isFalsy = aliases_and_guards_1.isFalsy; | ||
dist.isNullish = aliases_and_guards_1.isNullish; | ||
dist.isPrimitive = aliases_and_guards_1.isPrimitive; | ||
var functional_helpers_1 = requireFunctionalHelpers(); | ||
dist.getReturnOfExpression = functional_helpers_1.getReturnOfExpression; | ||
return dist; | ||
} | ||
var distExports = requireDist(); | ||
const isArray = Array.isArray; | ||
@@ -246,5 +265,5 @@ const isBoolean = isBoolean$1; | ||
const isSymbol = isSymbol$1; | ||
const isFalsy = isFalsy$1; | ||
const isNullish = isNullish$1; | ||
const isPrimitive = isPrimitive$1; | ||
const isFalsy = distExports.isFalsy; | ||
const isNullish = distExports.isNullish; | ||
const isPrimitive = distExports.isPrimitive; | ||
const isError = isError$1; | ||
@@ -292,52 +311,60 @@ const isNative = isNative$1; | ||
const isStringDate = (s) => !Number.isNaN(Date.parse(s)); | ||
var es6 = function equal(a, b) { | ||
if (a === b) return true; | ||
if (a && b && typeof a == "object" && typeof b == "object") { | ||
if (a.constructor !== b.constructor) return false; | ||
var length, i, keys2; | ||
if (Array.isArray(a)) { | ||
length = a.length; | ||
if (length != b.length) return false; | ||
var es6; | ||
var hasRequiredEs6; | ||
function requireEs6() { | ||
if (hasRequiredEs6) return es6; | ||
hasRequiredEs6 = 1; | ||
es6 = function equal(a, b) { | ||
if (a === b) return true; | ||
if (a && b && typeof a == "object" && typeof b == "object") { | ||
if (a.constructor !== b.constructor) return false; | ||
var length, i, keys2; | ||
if (Array.isArray(a)) { | ||
length = a.length; | ||
if (length != b.length) return false; | ||
for (i = length; i-- !== 0; ) | ||
if (!equal(a[i], b[i])) return false; | ||
return true; | ||
} | ||
if (a instanceof Map && b instanceof Map) { | ||
if (a.size !== b.size) return false; | ||
for (i of a.entries()) | ||
if (!b.has(i[0])) return false; | ||
for (i of a.entries()) | ||
if (!equal(i[1], b.get(i[0]))) return false; | ||
return true; | ||
} | ||
if (a instanceof Set && b instanceof Set) { | ||
if (a.size !== b.size) return false; | ||
for (i of a.entries()) | ||
if (!b.has(i[0])) return false; | ||
return true; | ||
} | ||
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { | ||
length = a.length; | ||
if (length != b.length) return false; | ||
for (i = length; i-- !== 0; ) | ||
if (a[i] !== b[i]) return false; | ||
return true; | ||
} | ||
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; | ||
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); | ||
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); | ||
keys2 = Object.keys(a); | ||
length = keys2.length; | ||
if (length !== Object.keys(b).length) return false; | ||
for (i = length; i-- !== 0; ) | ||
if (!equal(a[i], b[i])) return false; | ||
if (!Object.prototype.hasOwnProperty.call(b, keys2[i])) return false; | ||
for (i = length; i-- !== 0; ) { | ||
var key = keys2[i]; | ||
if (!equal(a[key], b[key])) return false; | ||
} | ||
return true; | ||
} | ||
if (a instanceof Map && b instanceof Map) { | ||
if (a.size !== b.size) return false; | ||
for (i of a.entries()) | ||
if (!b.has(i[0])) return false; | ||
for (i of a.entries()) | ||
if (!equal(i[1], b.get(i[0]))) return false; | ||
return true; | ||
} | ||
if (a instanceof Set && b instanceof Set) { | ||
if (a.size !== b.size) return false; | ||
for (i of a.entries()) | ||
if (!b.has(i[0])) return false; | ||
return true; | ||
} | ||
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { | ||
length = a.length; | ||
if (length != b.length) return false; | ||
for (i = length; i-- !== 0; ) | ||
if (a[i] !== b[i]) return false; | ||
return true; | ||
} | ||
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; | ||
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); | ||
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); | ||
keys2 = Object.keys(a); | ||
length = keys2.length; | ||
if (length !== Object.keys(b).length) return false; | ||
for (i = length; i-- !== 0; ) | ||
if (!Object.prototype.hasOwnProperty.call(b, keys2[i])) return false; | ||
for (i = length; i-- !== 0; ) { | ||
var key = keys2[i]; | ||
if (!equal(a[key], b[key])) return false; | ||
} | ||
return true; | ||
} | ||
return a !== a && b !== b; | ||
}; | ||
const fastDeepEqual = /* @__PURE__ */ getDefaultExportFromCjs(es6); | ||
return a !== a && b !== b; | ||
}; | ||
return es6; | ||
} | ||
var es6Exports = requireEs6(); | ||
const fastDeepEqual = /* @__PURE__ */ getDefaultExportFromCjs(es6Exports); | ||
const areSame = (a, b) => a === b; | ||
@@ -582,105 +609,119 @@ const areSimilar = (a, b) => a == b; | ||
const uniqueBy = (collection, matcher) => Array.isArray(collection) ? uniqueItemsBy(collection, matcher) : uniqueValuesBy(collection, matcher); | ||
var debounce$2 = { exports: {} }; | ||
function debounce$1(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(); | ||
} | ||
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_}\`.`); | ||
} | ||
} | ||
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."); | ||
if (wait < 0) { | ||
throw new RangeError("`wait` must not be negative."); | ||
} | ||
storedContext = this; | ||
storedArguments = arguments_; | ||
timestamp = Date.now(); | ||
const callNow = immediate && !timeoutId; | ||
if (!timeoutId) { | ||
timeoutId = setTimeout(later, wait); | ||
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; | ||
} | ||
if (callNow) { | ||
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(); | ||
} | ||
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; | ||
debounced.clear(); | ||
}; | ||
return debounced; | ||
} | ||
debounce$1.exports.debounce = debounce2; | ||
debounce$1.exports = debounce2; | ||
return debounce$1.exports; | ||
} | ||
debounce$2.exports.debounce = debounce$1; | ||
debounce$2.exports = debounce$1; | ||
var debounceExports = debounce$2.exports; | ||
var debounceExports = /* @__PURE__ */ requireDebounce(); | ||
const _debounce = /* @__PURE__ */ getDefaultExportFromCjs(debounceExports); | ||
function throttle$1(function_, wait) { | ||
if (typeof function_ !== "function") { | ||
throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof function_}\`.`); | ||
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); | ||
} | ||
}; | ||
} | ||
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 throttleit = throttle$1; | ||
const throttleit$1 = /* @__PURE__ */ getDefaultExportFromCjs(throttleit); | ||
var throttleitExports = /* @__PURE__ */ requireThrottleit(); | ||
const throttleit = /* @__PURE__ */ getDefaultExportFromCjs(throttleitExports); | ||
const debounce = _debounce; | ||
const throttle = throttleit$1; | ||
const throttle = throttleit; | ||
const once = (fn) => { | ||
@@ -687,0 +728,0 @@ let wasCalled = false; |
{ | ||
"name": "@webshrine/stdlib", | ||
"type": "module", | ||
"version": "0.0.0-alpha.4", | ||
"version": "0.0.0-alpha.5", | ||
"private": false, | ||
@@ -51,9 +51,9 @@ "repository": { | ||
"devDependencies": { | ||
"@types/node": "^22.9.0", | ||
"@types/node": "^22.10.1", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
"terser": "^5.36.0", | ||
"vite": "^5.4.11", | ||
"vite": "^6.0.1", | ||
"vite-plugin-dts": "^4.3.0", | ||
"vitest": "^2.1.5" | ||
"vitest": "^2.1.6" | ||
} | ||
} |
45793
1300