Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
b93ed45521 | |||
3e8f5cc00b | |||
54a2880391 | |||
b7aeee4706 | |||
b3eab0d6c9 | |||
ad4194a981 | |||
e1f22a01a6 | |||
91c0858d9f |
10
.github/workflows/build.yaml
vendored
10
.github/workflows/build.yaml
vendored
@ -48,3 +48,13 @@ jobs:
|
||||
uses: ztimson/actions/tag@develop
|
||||
with:
|
||||
tag: ${{env.VERSION}}
|
||||
|
||||
|
||||
docs:
|
||||
name: Publish Documentation
|
||||
needs: build
|
||||
uses: ztimson/actions/.github/workflows/docker.yaml@develop
|
||||
with:
|
||||
name: ztimson/utils
|
||||
repository: ${{github.server_url}}/${{github.repository}}.git
|
||||
pass: ${{secrets.DEPLOY_TOKEN}}
|
||||
|
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
# Build application
|
||||
FROM node:alpine as build
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN if [ ! -d "node_modules" ]; then npm i; fi && \
|
||||
if [ ! -d "dist" ]; then npm run docs; fi
|
||||
|
||||
# Use Nginx to serve
|
||||
FROM nginx:1.23-alpine
|
||||
|
||||
COPY --from=build /app/docs /usr/share/nginx/html
|
@ -20,7 +20,7 @@ Javascript/Typescript Utilities
|
||||
|
||||
---
|
||||
<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/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>
|
||||
@ -36,7 +36,7 @@ Javascript/Typescript Utilities
|
||||
- [Setup](#setup)
|
||||
- [Production](#production)
|
||||
- [Development](#development)
|
||||
- [Documentation](https://git.zakscode.com/ztimson/utils/wiki)
|
||||
- [Documentation](https://utils.docs.zakscode.com/)
|
||||
- [License](#license)
|
||||
|
||||
## About
|
||||
@ -82,7 +82,7 @@ A collection of utilities to make life a little easier
|
||||
|
||||
## Documentation
|
||||
|
||||
[Available Here](https://git.zakscode.com/ztimson/utils/wiki)
|
||||
[Available Here](https://utils.docs.zakscode.com/)
|
||||
|
||||
## License
|
||||
|
||||
|
1654
package-lock.json
generated
1654
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.16.10",
|
||||
"version": "0.18.0",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
@ -21,7 +21,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npx tsc && npx vite build",
|
||||
"docs": "typedoc --plugin typedoc-plugin-markdown --cleanOutputDir false --outputFileStrategy modules --hidePageHeader --out ./docs --entryPoints src/**/*.ts --readme none --entryFileName Home",
|
||||
"docs": "typedoc --cleanOutputDir false --out ./docs --entryPoints src/**/*.ts --readme none",
|
||||
"test": "npx jest",
|
||||
"test:coverage": "npx jest --coverage",
|
||||
"watch": "npx vite build --watch"
|
||||
@ -32,12 +32,14 @@
|
||||
"jest-junit": "^16.0.0",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typedoc": "^0.26.7",
|
||||
"typedoc-plugin-markdown": "^4.2.7",
|
||||
"typescript": "^5.3.3",
|
||||
"vite": "^5.0.12",
|
||||
"vite-plugin-dts": "^3.7.2"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"var-persist": "^1.0.1"
|
||||
}
|
||||
}
|
||||
|
16
src/aset.ts
16
src/aset.ts
@ -19,20 +19,22 @@ export class ASet<T> extends Array {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add single element to set if unique
|
||||
* @param {T} el Element to add
|
||||
* Add elements to set if unique
|
||||
* @param items
|
||||
*/
|
||||
add(el: T) {
|
||||
if(!this.has(el)) this.push(el);
|
||||
add(...items: T[]) {
|
||||
items.filter(el => !this.has(el)).forEach(el => this.push(el));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete element from set
|
||||
* @param {T} el Element that will be deleted
|
||||
* Delete elements from set
|
||||
* @param items Elements that will be deleted
|
||||
*/
|
||||
delete(el: T) {
|
||||
delete(...items: T[]) {
|
||||
items.forEach(el => {
|
||||
const index = this.indexOf(el);
|
||||
if(index != -1) this.slice(index, 1);
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,10 @@
|
||||
export type Listener = (...args: any[]) => any;
|
||||
export type TypedEvents = {[k in string | symbol]: Listener} & {'*': (event: string, ...args: any[]) => any};
|
||||
|
||||
export type NamespaceEvents<Namespace extends string, Events extends TypedEvents> = {
|
||||
[K in keyof Events as `${Namespace}:${Extract<K, string>}`]: Events[K];
|
||||
};
|
||||
|
||||
export class TypedEmitter<T extends TypedEvents = TypedEvents> {
|
||||
private static listeners: {[key: string]: Listener[]} = {};
|
||||
|
||||
|
@ -15,3 +15,4 @@ export * from './promise-progress';
|
||||
export * from './string';
|
||||
export * from './time';
|
||||
export * from './types';
|
||||
export * from 'var-persist';
|
||||
|
@ -36,14 +36,14 @@ export function sleep(ms: number): Promise<void> {
|
||||
* ```js
|
||||
* let loading = true;
|
||||
* 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 {number} checkInterval Run function ever x milliseconds
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user