@tldraw/utils
Advanced tools
Comparing version 0.0.2-alpha.1 to 0.1.0-alpha.2
@@ -21,2 +21,3 @@ "use strict"; | ||
__export(control_exports, { | ||
Result: () => Result, | ||
assert: () => assert, | ||
@@ -29,2 +30,10 @@ assertExists: () => assertExists, | ||
var import_function = require("./function"); | ||
const Result = { | ||
ok(value) { | ||
return { ok: true, value }; | ||
}, | ||
err(error) { | ||
return { ok: false, error }; | ||
} | ||
}; | ||
function exhaustiveSwitchError(value, property) { | ||
@@ -31,0 +40,0 @@ const debugValue = property && value && typeof value === "object" && property in value ? value[property] : value; |
@@ -22,3 +22,4 @@ "use strict"; | ||
getHashForObject: () => getHashForObject, | ||
getHashForString: () => getHashForString | ||
getHashForString: () => getHashForString, | ||
lns: () => lns | ||
}); | ||
@@ -37,2 +38,10 @@ module.exports = __toCommonJS(hash_exports); | ||
} | ||
function lns(str) { | ||
const result = str.split(""); | ||
result.push(...result.splice(0, Math.round(result.length / 5))); | ||
result.push(...result.splice(0, Math.round(result.length / 4))); | ||
result.push(...result.splice(0, Math.round(result.length / 3))); | ||
result.push(...result.splice(0, Math.round(result.length / 2))); | ||
return result.reverse().map((n) => +n ? +n < 5 ? 5 + +n : +n > 5 ? +n - 5 : n : n).join(""); | ||
} | ||
//# sourceMappingURL=hash.js.map |
@@ -21,2 +21,3 @@ "use strict"; | ||
__reExport(lib_exports, require("./debounce"), module.exports); | ||
__reExport(lib_exports, require("./error"), module.exports); | ||
__reExport(lib_exports, require("./function"), module.exports); | ||
@@ -23,0 +24,0 @@ __reExport(lib_exports, require("./hash"), module.exports); |
@@ -23,3 +23,6 @@ "use strict"; | ||
getOwnProperty: () => getOwnProperty, | ||
hasOwnProperty: () => hasOwnProperty | ||
hasOwnProperty: () => hasOwnProperty, | ||
objectMapEntries: () => objectMapEntries, | ||
objectMapKeys: () => objectMapKeys, | ||
objectMapValues: () => objectMapValues | ||
}); | ||
@@ -57,2 +60,11 @@ module.exports = __toCommonJS(object_exports); | ||
} | ||
function objectMapKeys(object) { | ||
return Object.keys(object); | ||
} | ||
function objectMapValues(object) { | ||
return Object.values(object); | ||
} | ||
function objectMapEntries(object) { | ||
return Object.entries(object); | ||
} | ||
//# sourceMappingURL=object.js.map |
import { omitFromStackTrace } from "./function"; | ||
const Result = { | ||
ok(value) { | ||
return { ok: true, value }; | ||
}, | ||
err(error) { | ||
return { ok: false, error }; | ||
} | ||
}; | ||
function exhaustiveSwitchError(value, property) { | ||
@@ -29,2 +37,3 @@ const debugValue = property && value && typeof value === "object" && property in value ? value[property] : value; | ||
export { | ||
Result, | ||
assert, | ||
@@ -31,0 +40,0 @@ assertExists, |
@@ -12,6 +12,15 @@ function getHashForString(string) { | ||
} | ||
function lns(str) { | ||
const result = str.split(""); | ||
result.push(...result.splice(0, Math.round(result.length / 5))); | ||
result.push(...result.splice(0, Math.round(result.length / 4))); | ||
result.push(...result.splice(0, Math.round(result.length / 3))); | ||
result.push(...result.splice(0, Math.round(result.length / 2))); | ||
return result.reverse().map((n) => +n ? +n < 5 ? 5 + +n : +n > 5 ? +n - 5 : n : n).join(""); | ||
} | ||
export { | ||
getHashForObject, | ||
getHashForString | ||
getHashForString, | ||
lns | ||
}; | ||
//# sourceMappingURL=hash.js.map |
export * from "./array"; | ||
export * from "./control"; | ||
export * from "./debounce"; | ||
export * from "./error"; | ||
export * from "./function"; | ||
@@ -5,0 +6,0 @@ export * from "./hash"; |
@@ -31,7 +31,19 @@ function hasOwnProperty(obj, key) { | ||
} | ||
function objectMapKeys(object) { | ||
return Object.keys(object); | ||
} | ||
function objectMapValues(object) { | ||
return Object.values(object); | ||
} | ||
function objectMapEntries(object) { | ||
return Object.entries(object); | ||
} | ||
export { | ||
deepCopy, | ||
getOwnProperty, | ||
hasOwnProperty | ||
hasOwnProperty, | ||
objectMapEntries, | ||
objectMapKeys, | ||
objectMapValues | ||
}; | ||
//# sourceMappingURL=object.js.map |
@@ -0,1 +1,3 @@ | ||
/* Excluded from this release type: annotateError */ | ||
/* Excluded from this release type: assert */ | ||
@@ -11,3 +13,5 @@ | ||
* @example | ||
* ```ts | ||
* const A = debounce(myFunction, 1000) | ||
* ``` | ||
* | ||
@@ -23,5 +27,2 @@ * | ||
* | ||
* @param input | ||
* @param equals | ||
* @returns | ||
* @public | ||
@@ -35,3 +36,5 @@ */ | ||
* @example | ||
* ```ts | ||
* const A = deepCopy({ a: 1, b: { c: 2 } }) | ||
* ``` | ||
* | ||
@@ -45,4 +48,17 @@ * @param obj - Target value to be copied. | ||
declare type ErrorAnnotations = { | ||
tags: Record<string, number | string | boolean | bigint | symbol | null | undefined>; | ||
extras: Record<string, unknown>; | ||
}; | ||
/** @public */ | ||
export declare type ErrorResult<E> = { | ||
readonly ok: false; | ||
readonly error: E; | ||
}; | ||
/* Excluded from this release type: exhaustiveSwitchError */ | ||
/* Excluded from this release type: getErrorAnnotations */ | ||
/** | ||
@@ -52,2 +68,3 @@ * Get the first item from an iterable Set or Map. | ||
* @example | ||
* ```ts | ||
* const A = getFirstItem(new Set([1, 2, 3])) // 1 | ||
@@ -60,2 +77,3 @@ * const B = getFirstItem( | ||
* ) // 1 | ||
* ``` | ||
* | ||
@@ -86,3 +104,3 @@ * @param value - The iterable Set or Map. | ||
* | ||
* @param value The value to check. | ||
* @param value - The value to check. | ||
* @public | ||
@@ -95,3 +113,3 @@ */ | ||
* | ||
* @param value The value to check. | ||
* @param value - The value to check. | ||
* @public | ||
@@ -104,3 +122,3 @@ */ | ||
* | ||
* @param value The value to check. | ||
* @param value - The value to check. | ||
* @public | ||
@@ -116,3 +134,5 @@ */ | ||
* @example | ||
* ```ts | ||
* const A = lerp(0, 1, 0.5) | ||
* ``` | ||
* | ||
@@ -123,2 +143,5 @@ * @public | ||
/** @public */ | ||
export declare function lns(str: string): string; | ||
/** | ||
@@ -128,3 +151,5 @@ * Modulate a value between two ranges. | ||
* @example | ||
* ```ts | ||
* const A = modulate(0, [0, 1], [0, 100]) | ||
* ``` | ||
* | ||
@@ -139,2 +164,14 @@ * @param value - The interpolation value. | ||
/* Excluded from this release type: objectMapEntries */ | ||
/* Excluded from this release type: objectMapKeys */ | ||
/* Excluded from this release type: objectMapValues */ | ||
/** @public */ | ||
export declare type OkResult<T> = { | ||
readonly ok: true; | ||
readonly value: T; | ||
}; | ||
/* Excluded from this release type: omitFromStackTrace */ | ||
@@ -144,2 +181,11 @@ | ||
/** @public */ | ||
export declare type Result<T, E> = OkResult<T> | ErrorResult<E>; | ||
/** @public */ | ||
export declare const Result: { | ||
ok<T>(value: T): OkResult<T>; | ||
err<E>(error: E): ErrorResult<E>; | ||
}; | ||
/** | ||
@@ -157,4 +203,2 @@ * Seeded random number generator, using [xorshift](https://en.wikipedia.org/wiki/Xorshift). The | ||
* | ||
* @param arr | ||
* @param offset | ||
* @public | ||
@@ -172,3 +216,5 @@ */ | ||
* @example | ||
* ```ts | ||
* const A = throttle(myFunction, 1000) | ||
* ``` | ||
* | ||
@@ -175,0 +221,0 @@ * @public |
@@ -5,3 +5,3 @@ { | ||
"description": "A tiny little drawing app (private utilities).", | ||
"version": "0.0.2-alpha.1", | ||
"version": "0.1.0-alpha.2", | ||
"author": "tldraw GB Ltd.", | ||
@@ -20,3 +20,2 @@ "homepage": "https://tldraw.dev", | ||
"dist/**/*", | ||
"src/**/*", | ||
"index.d.ts" | ||
@@ -23,0 +22,0 @@ ], |
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
71885
50
1017
1