1
0
Fork 0

feat: add checklist

This commit is contained in:
ssube 2020-03-29 09:10:40 -05:00
parent e530a99c31
commit 9c9a35c829
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
29 changed files with 515 additions and 1 deletions

View File

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ArrayMapperOptions](./js-utils.arraymapperoptions.md)
## ArrayMapperOptions interface
<b>Signature:</b>
```typescript
export interface ArrayMapperOptions
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [rest](./js-utils.arraymapperoptions.rest.md) | <code>string</code> | |
| [skip](./js-utils.arraymapperoptions.skip.md) | <code>number</code> | |
| [take](./js-utils.arraymapperoptions.take.md) | <code>Array&lt;string&gt;</code> | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ArrayMapperOptions](./js-utils.arraymapperoptions.md) &gt; [rest](./js-utils.arraymapperoptions.rest.md)
## ArrayMapperOptions.rest property
<b>Signature:</b>
```typescript
rest: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ArrayMapperOptions](./js-utils.arraymapperoptions.md) &gt; [skip](./js-utils.arraymapperoptions.skip.md)
## ArrayMapperOptions.skip property
<b>Signature:</b>
```typescript
skip: number;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ArrayMapperOptions](./js-utils.arraymapperoptions.md) &gt; [take](./js-utils.arraymapperoptions.take.md)
## ArrayMapperOptions.take property
<b>Signature:</b>
```typescript
take: Array<string>;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md) &gt; [args](./js-utils.childoptions.args.md)
## ChildOptions.args property
<b>Signature:</b>
```typescript
args: Array<string>;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md) &gt; [command](./js-utils.childoptions.command.md)
## ChildOptions.command property
<b>Signature:</b>
```typescript
command: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md) &gt; [cwd](./js-utils.childoptions.cwd.md)
## ChildOptions.cwd property
<b>Signature:</b>
```typescript
cwd: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md) &gt; [env](./js-utils.childoptions.env.md)
## ChildOptions.env property
<b>Signature:</b>
```typescript
env: Array<NameValuePair<string>>;
```

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md)
## ChildOptions interface
<b>Signature:</b>
```typescript
export interface ChildOptions
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [args](./js-utils.childoptions.args.md) | <code>Array&lt;string&gt;</code> | |
| [command](./js-utils.childoptions.command.md) | <code>string</code> | |
| [cwd](./js-utils.childoptions.cwd.md) | <code>string</code> | |
| [env](./js-utils.childoptions.env.md) | <code>Array&lt;NameValuePair&lt;string&gt;&gt;</code> | |
| [timeout](./js-utils.childoptions.timeout.md) | <code>number</code> | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildOptions](./js-utils.childoptions.md) &gt; [timeout](./js-utils.childoptions.timeout.md)
## ChildOptions.timeout property
<b>Signature:</b>
```typescript
timeout: number;
```

View File

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildResult](./js-utils.childresult.md)
## ChildResult interface
<b>Signature:</b>
```typescript
export interface ChildResult
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [status](./js-utils.childresult.status.md) | <code>number</code> | |
| [stderr](./js-utils.childresult.stderr.md) | <code>string</code> | |
| [stdout](./js-utils.childresult.stdout.md) | <code>string</code> | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildResult](./js-utils.childresult.md) &gt; [status](./js-utils.childresult.status.md)
## ChildResult.status property
<b>Signature:</b>
```typescript
status: number;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildResult](./js-utils.childresult.md) &gt; [stderr](./js-utils.childresult.stderr.md)
## ChildResult.stderr property
<b>Signature:</b>
```typescript
stderr: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildResult](./js-utils.childresult.md) &gt; [stdout](./js-utils.childresult.stdout.md)
## ChildResult.stdout property
<b>Signature:</b>
```typescript
stdout: string;
```

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [ChildSpawner](./js-utils.childspawner.md)
## ChildSpawner type
<b>Signature:</b>
```typescript
export declare type ChildSpawner = typeof spawn;
```

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [constructorName](./js-utils.constructorname.md)
## constructorName() function
<b>Signature:</b>
```typescript
export declare function constructorName(val: object): string;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>object</code> | |
<b>Returns:</b>
`string`

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [getConstructor](./js-utils.getconstructor.md)
## getConstructor() function
<b>Signature:</b>
```typescript
export declare function getConstructor(val: object): Function;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>object</code> | |
<b>Returns:</b>
`Function`

View File

@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [getHead](./js-utils.gethead.md)
## getHead() function
<b>Signature:</b>
```typescript
export declare function getHead<TKey, TVal>(map: Map<TKey, Array<TVal>>, key: TKey): TVal;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| map | <code>Map&lt;TKey, Array&lt;TVal&gt;&gt;</code> | |
| key | <code>TKey</code> | |
<b>Returns:</b>
`TVal`

View File

@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [getHeadOrDefault](./js-utils.getheadordefault.md)
## getHeadOrDefault() function
<b>Signature:</b>
```typescript
export declare function getHeadOrDefault<TKey, TVal>(map: Map<TKey, Array<Optional<TVal>>>, key: TKey, defaultValue: TVal): TVal;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| map | <code>Map&lt;TKey, Array&lt;Optional&lt;TVal&gt;&gt;&gt;</code> | |
| key | <code>TKey</code> | |
| defaultValue | <code>TVal</code> | |
<b>Returns:</b>
`TVal`

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [getMethods](./js-utils.getmethods.md)
## getMethods() function
<b>Signature:</b>
```typescript
export declare function getMethods<TValue extends object>(value: TValue): Set<Function>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| value | <code>TValue</code> | |
<b>Returns:</b>
`Set<Function>`

View File

@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [getOrDefault](./js-utils.getordefault.md)
## getOrDefault() function
<b>Signature:</b>
```typescript
export declare function getOrDefault<TKey, TVal>(map: Map<TKey, TVal>, key: TKey, defaultValue: TVal): TVal;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| map | <code>Map&lt;TKey, TVal&gt;</code> | |
| key | <code>TKey</code> | |
| defaultValue | <code>TVal</code> | |
<b>Returns:</b>
`TVal`

View File

@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [leftPad](./js-utils.leftpad.md)
## leftPad() function
<b>Signature:</b>
```typescript
export declare function leftPad(val: string, min?: number, fill?: string): string;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>string</code> | |
| min | <code>number</code> | |
| fill | <code>string</code> | |
<b>Returns:</b>
`string`

View File

@ -22,6 +22,7 @@
| Function | Description |
| --- | --- |
| [concat(chunks)](./js-utils.concat.md) | |
| [constructorName(val)](./js-utils.constructorname.md) | |
| [countOf(val)](./js-utils.countof.md) | Calculate the "length" of an array or value.<!-- -->Arrays return their length, single values return 1, and nil values return 0. This counts the number of elements that setOrPush would add. |
| [defaultWhen(condition, items)](./js-utils.defaultwhen.md) | |
| [defer(ms, val)](./js-utils.defer.md) | Resolve after a set amount of time. |
@ -29,9 +30,15 @@
| [encode(chunks, encoding)](./js-utils.encode.md) | |
| [entriesOf(map)](./js-utils.entriesof.md) | |
| [filterNil(list)](./js-utils.filternil.md) | Remove any null or undefined items from the list. |
| [getConstructor(val)](./js-utils.getconstructor.md) | |
| [getHead(map, key)](./js-utils.gethead.md) | |
| [getHeadOrDefault(map, key, defaultValue)](./js-utils.getheadordefault.md) | |
| [getMethods(value)](./js-utils.getmethods.md) | |
| [getOrDefault(map, key, defaultValue)](./js-utils.getordefault.md) | |
| [getTestLogger(verbose)](./js-utils.gettestlogger.md) | |
| [isDebug()](./js-utils.isdebug.md) | |
| [isNil(val)](./js-utils.isnil.md) | |
| [leftPad(val, min, fill)](./js-utils.leftpad.md) | |
| [makeDict(map)](./js-utils.makedict.md) | Turns a map or dict into a dict |
| [makeMap(val)](./js-utils.makemap.md) | Clone a map or map-like object into a new map. |
| [mergeList(parts)](./js-utils.mergelist.md) | Merge arguments, which may or may not be arrays, into one return that is definitely an array. |
@ -40,19 +47,26 @@
| [mustExist(val)](./js-utils.mustexist.md) | Assert that a variable is not nil and return the value. |
| [mustFind(list, predicate)](./js-utils.mustfind.md) | Find a value matching the given predicate or throw. |
| [mustGet(map, key)](./js-utils.mustget.md) | Get an element from a Map and guard against nil values. |
| [normalizeMap(map)](./js-utils.normalizemap.md) | |
| [pairsToMap(pairs)](./js-utils.pairstomap.md) | |
| [pushMergeMap(args)](./js-utils.pushmergemap.md) | |
| [removePid(path)](./js-utils.removepid.md) | |
| [setOrPush(map, key, val)](./js-utils.setorpush.md) | Set a map key to a new array or push to the existing value. |
| [signal(signals)](./js-utils.signal.md) | |
| [spyLogger(spies)](./js-utils.spylogger.md) | |
| [timeout(ms, oper)](./js-utils.timeout.md) | Reject after a set amount of time if the original promise has not yet resolved. |
| [trim(val, max, tail)](./js-utils.trim.md) | |
| [waitForChild(child)](./js-utils.waitforchild.md) | |
| [writePid(path)](./js-utils.writepid.md) | |
| [writeValue(stream, value)](./js-utils.writevalue.md) | |
## Interfaces
| Interface | Description |
| --- | --- |
| [ArrayMapperOptions](./js-utils.arraymapperoptions.md) | |
| [ChildOptions](./js-utils.childoptions.md) | |
| [ChildResult](./js-utils.childresult.md) | |
| [Dict](./js-utils.dict.md) | |
| [ExternalModule](./js-utils.externalmodule.md) | |
@ -68,6 +82,7 @@
| Type Alias | Description |
| --- | --- |
| [ChildSpawner](./js-utils.childspawner.md) | |
| [MapLike](./js-utils.maplike.md) | A <code>Map</code> or dictionary object with string keys and <code>TVal</code> values. |
| [ModuleCtor](./js-utils.modulector.md) | |
| [Nil](./js-utils.nil.md) | Unset value. |

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [normalizeMap](./js-utils.normalizemap.md)
## normalizeMap() function
<b>Signature:</b>
```typescript
export declare function normalizeMap(map: MapLike<unknown>): Dict<Array<string>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| map | <code>MapLike&lt;unknown&gt;</code> | |
<b>Returns:</b>
`Dict<Array<string>>`

View File

@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [pairsToMap](./js-utils.pairstomap.md)
## pairsToMap() function
<b>Signature:</b>
```typescript
export declare function pairsToMap<TVal>(pairs: Array<NameValuePair<TVal>>): Map<string, TVal>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| pairs | <code>Array&lt;NameValuePair&lt;TVal&gt;&gt;</code> | |
<b>Returns:</b>
`Map<string, TVal>`

24
docs/api/js-utils.trim.md Normal file
View File

@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [trim](./js-utils.trim.md)
## trim() function
<b>Signature:</b>
```typescript
export declare function trim(val: string, max: number, tail?: string): string;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>string</code> | |
| max | <code>number</code> | |
| tail | <code>string</code> | |
<b>Returns:</b>
`string`

View File

@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [@apextoaster/js-utils](./js-utils.md) &gt; [writeValue](./js-utils.writevalue.md)
## writeValue() function
<b>Signature:</b>
```typescript
export declare function writeValue(stream: Writable, value: string): Promise<boolean>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| stream | <code>Writable</code> | |
| value | <code>string</code> | |
<b>Returns:</b>
`Promise<boolean>`

View File

@ -28,6 +28,7 @@ export {
} from './utils';
export {
ArrayMapper,
ArrayMapperOptions,
} from './utils/ArrayMapper';
export {
defer,
@ -37,17 +38,33 @@ export {
concat,
encode,
} from './utils/Buffer';
export { waitForChild } from './utils/Child';
export {
Checklist,
ChecklistMode,
ChecklistOptions,
} from './utils/Checklist';
export {
ChildOptions,
ChildResult,
ChildSpawner,
waitForChild,
writeValue,
} from './utils/Child';
export { ExternalModule, ModuleCtor } from './utils/ExternalModule';
export { isDebug } from './utils/Env';
export {
Dict,
MapLike,
entriesOf,
getHead,
getHeadOrDefault,
getOrDefault,
makeDict,
makeMap,
mergeMap,
mustGet,
normalizeMap,
pairsToMap,
pushMergeMap,
setOrPush,
} from './utils/Map';
@ -56,6 +73,7 @@ export {
writePid,
} from './utils/PidFile';
export {
constructorName,
getConstructor,
getMethods,
} from './utils/Reflect';
@ -65,3 +83,7 @@ export {
SIGNAL_STOP,
signal,
} from './utils/Signal';
export {
leftPad,
trim,
} from './utils/String';

31
src/utils/Checklist.ts Normal file
View File

@ -0,0 +1,31 @@
export enum ChecklistMode {
INCLUDE = 'include',
EXCLUDE = 'exclude',
}
export interface ChecklistOptions<T> {
data: Array<T>;
mode: ChecklistMode;
}
export class Checklist<T> implements ChecklistOptions<T> {
public readonly data: Array<T>;
public readonly mode: ChecklistMode;
constructor(options: ChecklistOptions<T>) {
this.data = Array.from(options.data);
this.mode = options.mode;
}
public check(value: T): boolean {
if (this.mode === ChecklistMode.INCLUDE) {
return this.data.includes(value);
}
if (this.mode === ChecklistMode.EXCLUDE) {
return !this.data.includes(value);
}
return false;
}
}