@bffr/tools
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -6,2 +6,4 @@ export declare const and: { | ||
value: typeof andV; | ||
includes: typeof andV; | ||
keyin: typeof andK; | ||
}; | ||
@@ -20,1 +22,3 @@ /** | ||
export declare function andK<T extends string>(source: unknown, value?: T): T | undefined; | ||
export declare const includes: typeof andV; | ||
export declare const keyin: typeof andK; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.andK = exports.andV = exports.and = void 0; | ||
exports.keyin = exports.includes = exports.andK = exports.andV = exports.and = void 0; | ||
// this is getting a little ridiculous right? | ||
exports.and = { | ||
@@ -9,2 +10,4 @@ k: andK, | ||
value: andV, | ||
includes: andV, | ||
keyin: andK, | ||
}; | ||
@@ -39,2 +42,4 @@ /** | ||
exports.andK = andK; | ||
exports.includes = andV; | ||
exports.keyin = andK; | ||
//# sourceMappingURL=and.js.map |
@@ -12,3 +12,5 @@ /** | ||
export * from './guard'; | ||
export * from './idle'; | ||
export * from './json'; | ||
export * from './match'; | ||
export * from './number'; | ||
@@ -19,4 +21,3 @@ export * from './object'; | ||
export * from './timer'; | ||
export * from './match'; | ||
export { boolean as bool } from './boolean'; | ||
export { promise as prom } from './promise'; |
@@ -29,3 +29,5 @@ "use strict"; | ||
__exportStar(require("./guard"), exports); | ||
__exportStar(require("./idle"), exports); | ||
__exportStar(require("./json"), exports); | ||
__exportStar(require("./match"), exports); | ||
__exportStar(require("./number"), exports); | ||
@@ -36,3 +38,2 @@ __exportStar(require("./object"), exports); | ||
__exportStar(require("./timer"), exports); | ||
__exportStar(require("./match"), exports); | ||
var boolean_1 = require("./boolean"); | ||
@@ -39,0 +40,0 @@ Object.defineProperty(exports, "bool", { enumerable: true, get: function () { return boolean_1.boolean; } }); |
@@ -5,8 +5,1 @@ export declare type Timer<T> = (fn: () => unknown, duration: number) => T; | ||
export declare function createTimer<T>(set: Timer<T>, clear: (v: T) => unknown): Timer<() => void>; | ||
export declare type CreateIdleCallbackProps<T> = IdleRequestOptions & { | ||
fallback?: (effect: T, options: IdleRequestOptions) => () => void; | ||
}; | ||
export declare function createIdleCallback<T extends IdleRequestCallback>(effect: T, { fallback, ...options }?: CreateIdleCallbackProps<T>): () => void; | ||
export declare namespace createIdleCallback { | ||
var timeout: number; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createIdleCallback = exports.createTimer = exports.createInterval = exports.createTimeout = void 0; | ||
exports.createTimer = exports.createInterval = exports.createTimeout = void 0; | ||
exports.createTimeout = createTimer(setTimeout, clearTimeout); | ||
@@ -14,27 +14,2 @@ exports.createInterval = createTimer(setInterval, clearInterval); | ||
exports.createTimer = createTimer; | ||
const requestIdleCallback = window?.requestIdleCallback; | ||
function createIdleCallback(effect, { fallback, ...options } = {}) { | ||
options = { timeout: createIdleCallback.timeout, ...options }; | ||
// not supported by all browsers or environments | ||
if (requestIdleCallback != null) { | ||
const id = requestIdleCallback(a => effect?.(a), options); | ||
return () => window.cancelIdleCallback(id); | ||
} | ||
// takes optional fallback | ||
else if (typeof fallback === 'function') { | ||
const timer = fallback(effect, options); | ||
// requires the fallbacks to return a timer cancelation | ||
if (typeof timer !== 'function') | ||
throw new Error('createIdleCallback expected a cancelation `() => void` be returned from fallback'); | ||
else | ||
return timer; | ||
} | ||
// otherwise defaults to setTimeout | ||
else { | ||
const id = setTimeout(effect, options.timeout); | ||
return () => clearTimeout(id); | ||
} | ||
} | ||
exports.createIdleCallback = createIdleCallback; | ||
createIdleCallback.timeout = 4 * 16; | ||
//# sourceMappingURL=timer.js.map |
{ | ||
"name": "@bffr/tools", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Hammers, saws, and more pure function tools.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -0,1 +1,2 @@ | ||
// this is getting a little ridiculous right? | ||
export const and = { | ||
@@ -6,2 +7,4 @@ k: andK, | ||
value: andV, | ||
includes: andV, | ||
keyin: andK, | ||
}; | ||
@@ -36,1 +39,4 @@ | ||
} | ||
export const includes = andV; | ||
export const keyin = andK; |
@@ -12,3 +12,5 @@ /** | ||
export * from './guard'; | ||
export * from './idle'; | ||
export * from './json'; | ||
export * from './match'; | ||
export * from './number'; | ||
@@ -19,5 +21,4 @@ export * from './object'; | ||
export * from './timer'; | ||
export * from './match'; | ||
export { boolean as bool } from './boolean'; | ||
export { promise as prom } from './promise'; |
@@ -17,36 +17,1 @@ export type Timer<T> = (fn: () => unknown, duration: number) => T; | ||
} | ||
export type CreateIdleCallbackProps<T> = IdleRequestOptions & { | ||
fallback?: (effect: T, options: IdleRequestOptions) => () => void; | ||
}; | ||
const requestIdleCallback = window?.requestIdleCallback; | ||
export function createIdleCallback<T extends IdleRequestCallback>( | ||
effect: T, | ||
{ fallback, ...options }: CreateIdleCallbackProps<T> = {}, | ||
) { | ||
options = { timeout: createIdleCallback.timeout, ...options }; | ||
// not supported by all browsers or environments | ||
if (requestIdleCallback != null) { | ||
const id = requestIdleCallback(a => effect?.(a), options); | ||
return () => window.cancelIdleCallback(id); | ||
} | ||
// takes optional fallback | ||
else if (typeof fallback === 'function') { | ||
const timer = fallback(effect, options); | ||
// requires the fallbacks to return a timer cancelation | ||
if (typeof timer !== 'function') | ||
throw new Error( | ||
'createIdleCallback expected a cancelation `() => void` be returned from fallback', | ||
); | ||
else return timer; | ||
} | ||
// otherwise defaults to setTimeout | ||
else { | ||
const id = setTimeout(effect, options.timeout); | ||
return () => clearTimeout(id); | ||
} | ||
} | ||
createIdleCallback.timeout = 4 * 16; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
71700
75
1509