vest-utils 0.1.0-dev-c4ba9b → 0.1.0-dev-405df5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ import optionalFunctionValue from 'optionalFunctionValue';
2
+
3
+ export function createTinyState<S>(initialValue: S | (() => S)): TinyState<S> {
4
+ let value: S;
5
+
6
+ resetValue();
7
+
8
+ return () => [value, setValue, resetValue];
9
+
10
+ function setValue(nextValue: S | ((currentValue: S) => S)) {
11
+ value = optionalFunctionValue(nextValue, value);
12
+ }
13
+
14
+ function resetValue() {
15
+ setValue(optionalFunctionValue(initialValue));
16
+ }
17
+ }
18
+
19
+ export type TinyState<S> = () => [
20
+ value: S,
21
+ setValue: (next: S | ((prev: S) => S)) => void,
22
+ resetValue: () => void
23
+ ];
package/src/vest-utils.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { default as cache } from 'cache';
1
+ export { default as cache, CacheApi } from 'cache';
2
+ export { BusType } from 'bus';
3
+ export { TinyState } from 'tinyState';
2
4
  export { isNullish, isNotNullish } from 'isNullish';
3
5
  export * as nestedArray from 'nestedArray';
4
6
  export { default as asArray } from 'asArray';
@@ -16,7 +18,7 @@ export { default as isBoolean } from 'isBooleanValue';
16
18
  export { default as last } from 'last';
17
19
  export { default as deferThrow } from 'deferThrow';
18
20
  export * as bus from 'bus';
19
- export { default as seq } from 'seq';
21
+ export { default as seq, genSeq } from 'seq';
20
22
  export { default as isFunction } from 'isFunction';
21
23
  export { default as mapFirst } from 'mapFirst';
22
24
  export { greaterThan } from 'greaterThan';
@@ -29,6 +31,7 @@ export { isUndefined, isNotUndefined } from 'isUndefined';
29
31
  export { isArray, isNotArray } from 'isArrayValue';
30
32
  export { isEmpty, isNotEmpty } from 'isEmpty';
31
33
  export { isPositive } from 'isPositive';
34
+ export * as tinyState from 'tinyState';
32
35
 
33
36
  export type { DropFirst } from 'utilityTypes';
34
37
  export type { Stringable } from 'utilityTypes';
package/tsconfig.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "rootDir": ".",
4
4
  "compilerOptions": {
5
5
  "baseUrl": ".",
6
- "declarationMap": true,
7
6
  "declarationDir": "./types",
7
+ "declarationMap": true,
8
8
  "outDir": "./dist",
9
9
  "paths": {
10
10
  "asArray": ["src/asArray.ts"],
@@ -39,6 +39,7 @@
39
39
  "numberEquals": ["src/numberEquals.ts"],
40
40
  "optionalFunctionValue": ["src/optionalFunctionValue.ts"],
41
41
  "seq": ["src/seq.ts"],
42
+ "tinyState": ["src/tinyState.ts"],
42
43
  "utilityTypes": ["src/utilityTypes.ts"],
43
44
  "vest-utils": ["src/vest-utils.ts"]
44
45
  }
@@ -1,11 +1,41 @@
1
1
  /**
2
2
  * Creates a cache function
3
3
  */
4
- declare function createCache(maxSize?: number): {
5
- <T>(deps: unknown[], cacheAction: (...args: unknown[]) => T): T;
6
- get(deps: unknown[]): any;
4
+ declare function createCache<T = unknown>(maxSize?: number): {
5
+ (deps: unknown[], cacheAction: (...args: unknown[]) => T): T;
6
+ get(deps: unknown[]): [
7
+ unknown[],
8
+ T
9
+ ] | null;
7
10
  invalidate(item: any): void;
8
11
  };
12
+ type CacheApi<T = unknown> = {
13
+ (deps: unknown[], cacheAction: (...args: unknown[]) => T): T;
14
+ get(deps: unknown[]): [
15
+ unknown[],
16
+ T
17
+ ] | null;
18
+ invalidate(item: any): void;
19
+ };
20
+ type DropFirst<T extends unknown[]> = T extends [
21
+ unknown,
22
+ ...infer U
23
+ ] ? U : never;
24
+ type Stringable = string | ((...args: any[]) => string);
25
+ type CB = (...args: any[]) => any;
26
+ type ValueOf<T> = T[keyof T];
27
+ type OnReturn = {
28
+ off: () => void;
29
+ };
30
+ type BusType = {
31
+ on: (event: string, handler: CB) => OnReturn;
32
+ emit: (event: string, ...args: any[]) => void;
33
+ };
34
+ type TinyState<S> = () => [
35
+ value: S,
36
+ setValue: (next: S | ((prev: S) => S)) => void,
37
+ resetValue: () => void
38
+ ];
9
39
  declare function isNullish(value: any): value is null | undefined;
10
40
  declare const isNotNullish: (value: any) => boolean;
11
41
  declare namespace nestedArray {
@@ -20,13 +50,6 @@ declare namespace nestedArray {
20
50
  function getCurrent<T>(array: NestedArray<T>, path: number[]): NestedArray<T>;
21
51
  }
22
52
  declare function asArray<T>(possibleArg: T | T[]): T[];
23
- type DropFirst<T extends unknown[]> = T extends [
24
- unknown,
25
- ...infer U
26
- ] ? U : never;
27
- type Stringable = string | ((...args: any[]) => string);
28
- type CB = (...args: any[]) => any;
29
- type ValueOf<T> = T[keyof T];
30
53
  declare function callEach(arr: CB[]): void;
31
54
  /**
32
55
  * A safe hasOwnProperty access
@@ -60,18 +83,20 @@ declare namespace bus {
60
83
  type Stringable = string | ((...args: any[]) => string);
61
84
  type CB = (...args: any[]) => any;
62
85
  type ValueOf<T> = T[keyof T];
63
- function createBus(): {
64
- on: (event: string, handler: CB) => OnReturn;
65
- emit: (event: string, ...args: any[]) => void;
66
- };
86
+ function createBus(): BusType;
67
87
  type OnReturn = {
68
88
  off: () => void;
69
89
  };
90
+ type BusType = {
91
+ on: (event: string, handler: CB) => OnReturn;
92
+ emit: (event: string, ...args: any[]) => void;
93
+ };
70
94
  }
71
95
  /**
72
96
  * @returns a unique numeric id.
73
97
  */
74
98
  declare const seq: () => string;
99
+ declare function genSeq(namespace?: string): () => string;
75
100
  declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
76
101
  declare function mapFirst<T>(array: T[], callback: (item: T, breakout: (conditional: boolean, value: unknown) => void, index: number) => unknown): any;
77
102
  declare function greaterThan(value: number | string, gt: number | string): boolean;
@@ -94,6 +119,14 @@ declare const isNotArray: (value: unknown) => boolean;
94
119
  declare function isEmpty(value: unknown): boolean;
95
120
  declare const isNotEmpty: (value: unknown) => boolean;
96
121
  declare function isPositive(value: number | string): boolean;
97
- export { createCache as cache, isNullish, isNotNullish, nestedArray, asArray, callEach, hasOwnProperty, isPromise, optionalFunctionValue, _default as assign, defaultTo, invariant, StringObject, isStringValue, bindNot, either, isBoolean, last, deferThrow, bus, seq, isFunction, mapFirst, greaterThan, longerThan, isNumeric, isNotNumeric, lengthEquals, lengthNotEquals, numberEquals, numberNotEquals, isNull, isNotNull, isUndefined, isNotUndefined, isArray, isNotArray, isEmpty, isNotEmpty, isPositive };
122
+ declare namespace tinyState {
123
+ function createTinyState<S>(initialValue: S | (() => S)): TinyState<S>;
124
+ type TinyState<S> = () => [
125
+ value: S,
126
+ setValue: (next: S | ((prev: S) => S)) => void,
127
+ resetValue: () => void
128
+ ];
129
+ }
130
+ export { createCache as cache, CacheApi, BusType, TinyState, isNullish, isNotNullish, nestedArray, asArray, callEach, hasOwnProperty, isPromise, optionalFunctionValue, _default as assign, defaultTo, invariant, StringObject, isStringValue, bindNot, either, isBoolean, last, deferThrow, bus, seq, genSeq, isFunction, mapFirst, greaterThan, longerThan, isNumeric, isNotNumeric, lengthEquals, lengthNotEquals, numberEquals, numberNotEquals, isNull, isNotNull, isUndefined, isNotUndefined, isArray, isNotArray, isEmpty, isNotEmpty, isPositive, tinyState };
98
131
  export type { DropFirst, Stringable, CB, ValueOf };
99
132
  //# sourceMappingURL=vest-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vest-utils.d.ts","sourceRoot":"","sources":["../src/vest-utils.ts","../src/bindNot.ts","../src/isNumeric.ts","../src/numberEquals.ts","../src/lengthEquals.ts","../src/greaterThan.ts","../src/longerThan.ts","../src/cache.ts","../src/isNull.ts","../src/isUndefined.ts","../src/isNullish.ts","../src/asArray.ts","../src/isFunction.ts","../src/optionalFunctionValue.ts","../src/defaultTo.ts","../src/isArrayValue.ts","../src/last.ts","../src/nestedArray.ts","../src/utilityTypes.ts","../src/callEach.ts","../src/hasOwnProperty.ts","../src/isPromise.ts","../src/assign.ts","../src/invariant.ts","../src/isStringValue.ts","../src/either.ts","../src/isBooleanValue.ts","../src/deferThrow.ts","../src/bus.ts","../src/seq.ts","../src/mapFirst.ts","../src/isEmpty.ts","../src/isPositive.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,8eAAoB,CAAc;AAgCzC,YAAY,sCAAa,CAAqB"}
1
+ {"version":3,"file":"vest-utils.d.ts","sourceRoot":"","sources":["../src/vest-utils.ts","../src/bindNot.ts","../src/isNumeric.ts","../src/numberEquals.ts","../src/lengthEquals.ts","../src/greaterThan.ts","../src/longerThan.ts","../src/cache.ts","../src/utilityTypes.ts","../src/bus.ts","../src/isFunction.ts","../src/optionalFunctionValue.ts","../src/tinyState.ts","../src/isNull.ts","../src/isUndefined.ts","../src/isNullish.ts","../src/asArray.ts","../src/defaultTo.ts","../src/isArrayValue.ts","../src/last.ts","../src/nestedArray.ts","../src/callEach.ts","../src/hasOwnProperty.ts","../src/isPromise.ts","../src/assign.ts","../src/invariant.ts","../src/isStringValue.ts","../src/either.ts","../src/isBooleanValue.ts","../src/deferThrow.ts","../src/seq.ts","../src/mapFirst.ts","../src/isEmpty.ts","../src/isPositive.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,+hBAA8B,CAAc;AAmCnD,YAAY,sCAAa,CAAqB"}