Compare commits

..

5 Commits

Author SHA1 Message Date
c51239d12b Bump 0.18.2
All checks were successful
Build / Build NPM Project (push) Successful in 25s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 26s
2024-10-12 12:30:23 -04:00
e4229296c1 Added escapeRegex
All checks were successful
Build / Build NPM Project (push) Successful in 59s
Build / Tag Version (push) Successful in 14s
Build / Publish Documentation (push) Successful in 42s
2024-10-12 12:27:45 -04:00
b93ed45521 Renamed sleepUntil to sleepWhile, it was misleading
All checks were successful
Build / Build NPM Project (push) Successful in 1m5s
Build / Tag Version (push) Successful in 14s
Build / Publish Documentation (push) Successful in 39s
2024-10-07 15:40:14 -04:00
3e8f5cc00b Add or remove multiple elements from ASet at once
All checks were successful
Build / Build NPM Project (push) Successful in 30s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 27s
2024-10-06 19:14:36 -04:00
54a2880391 Updated docs
All checks were successful
Build / Build NPM Project (push) Successful in 27s
Build / Tag Version (push) Successful in 7s
Build / Publish Documentation (push) Successful in 25s
2024-10-01 15:44:49 -04:00
6 changed files with 29 additions and 30 deletions

View File

@ -20,7 +20,7 @@ Javascript/Typescript Utilities
--- ---
<div> <div>
<a href="https://git.zakscode.com/ztimson/utils/wiki" target="_blank">Documentation</a> <a href="https://utils.docs.zakscode.com" target="_blank">Documentation</a>
<a href="https://git.zakscode.com/ztimson/utils/releases" target="_blank">Release Notes</a> <a href="https://git.zakscode.com/ztimson/utils/releases" target="_blank">Release Notes</a>
<a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a> <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fbug.md" target="_blank">Report a Bug</a>
<a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a> <a href="https://git.zakscode.com/ztimson/utils/issues/new?template=.github%2fissue_template%2fenhancement.md" target="_blank">Request a Feature</a>
@ -36,7 +36,7 @@ Javascript/Typescript Utilities
- [Setup](#setup) - [Setup](#setup)
- [Production](#production) - [Production](#production)
- [Development](#development) - [Development](#development)
- [Documentation](https://git.zakscode.com/ztimson/utils/wiki) - [Documentation](https://utils.docs.zakscode.com/)
- [License](#license) - [License](#license)
## About ## About
@ -82,7 +82,7 @@ A collection of utilities to make life a little easier
## Documentation ## Documentation
[Available Here](https://git.zakscode.com/ztimson/utils/wiki) [Available Here](https://utils.docs.zakscode.com/)
## License ## License

17
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.0", "version": "0.18.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.0", "version": "0.18.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"var-persist": "^1.0.1" "var-persist": "^1.0.1"
@ -17,7 +17,6 @@
"jest-junit": "^16.0.0", "jest-junit": "^16.0.0",
"ts-jest": "^29.1.2", "ts-jest": "^29.1.2",
"typedoc": "^0.26.7", "typedoc": "^0.26.7",
"typedoc-plugin-markdown": "^4.2.7",
"typescript": "^5.3.3", "typescript": "^5.3.3",
"vite": "^5.0.12", "vite": "^5.0.12",
"vite-plugin-dts": "^3.7.2" "vite-plugin-dts": "^3.7.2"
@ -5233,18 +5232,6 @@
"typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x" "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x"
} }
}, },
"node_modules/typedoc-plugin-markdown": {
"version": "4.2.8",
"resolved": "https://registry.npmjs.org/typedoc-plugin-markdown/-/typedoc-plugin-markdown-4.2.8.tgz",
"integrity": "sha512-1EDsc66jaCjZtxdYy+Rl0KDU1WY/iyuCOOPaeFzcYFZ81FNXV8CmgUDOHri20WGmYnkEM5nQ+ooxj1vyuQo0Lg==",
"dev": true,
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"typedoc": "0.26.x"
}
},
"node_modules/typedoc/node_modules/brace-expansion": { "node_modules/typedoc/node_modules/brace-expansion": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ztimson/utils", "name": "@ztimson/utils",
"version": "0.17.0", "version": "0.18.2",
"description": "Utility library", "description": "Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@ -19,20 +19,22 @@ export class ASet<T> extends Array {
} }
/** /**
* Add single element to set if unique * Add elements to set if unique
* @param {T} el Element to add * @param items
*/ */
add(el: T) { add(...items: T[]) {
if(!this.has(el)) this.push(el); items.filter(el => !this.has(el)).forEach(el => this.push(el));
} }
/** /**
* Delete element from set * Delete elements from set
* @param {T} el Element that will be deleted * @param items Elements that will be deleted
*/ */
delete(el: T) { delete(...items: T[]) {
const index = this.indexOf(el); items.forEach(el => {
if(index != -1) this.slice(index, 1); const index = this.indexOf(el);
if(index != -1) this.slice(index, 1);
})
} }
/** /**

View File

@ -11,3 +11,13 @@ export function gravatar(email: string, def='mp') {
if(!email) return ''; if(!email) return '';
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`; return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
} }
/**
* Escape any regex special characters to avoid misinterpretation during search
*
* @param {string} value String which should be escaped
* @return {string} New escaped sequence
*/
export function escapeRegex(value: string) {
return value.replace(/[.*+?^${}()|\[\]\\]/g, '\\$&');
}

View File

@ -36,14 +36,14 @@ export function sleep(ms: number): Promise<void> {
* ```js * ```js
* let loading = true; * let loading = true;
* setTimeout(() => wait = false, 1000); * setTimeout(() => wait = false, 1000);
* await sleepUntil(() => loading); // Won't continue until loading flag is false * await sleepWhile(() => loading); // Won't continue until loading flag is false
* ``` * ```
* *
* @param {() => boolean | Promise<boolean>} fn Return true to continue * @param {() => boolean | Promise<boolean>} fn Return true to continue
* @param {number} checkInterval Run function ever x milliseconds * @param {number} checkInterval Run function ever x milliseconds
* @return {Promise<void>} Callback when sleep is over * @return {Promise<void>} Callback when sleep is over
*/ */
export async function sleepUntil(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> { export async function sleepWhile(fn : () => boolean | Promise<boolean>, checkInterval = 100): Promise<void> {
while(await fn()) await sleep(checkInterval); while(await fn()) await sleep(checkInterval);
} }