@inrixia/helpers 2.0.2 → 2.0.3
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.
- package/README.md +1 -0
- package/package.json +44 -8
- package/{conv.js → src/conv.ts} +15 -13
- package/src/elastic.ts +141 -0
- package/src/geo.ts +33 -0
- package/{index.js → src/index.ts} +9 -10
- package/src/logic.ts +52 -0
- package/{math.js → src/math.ts} +20 -19
- package/src/object.ts +349 -0
- package/src/react.ts +11 -0
- package/src/test/matchers.ts +76 -0
- package/src/test.ts +14 -0
- package/src/ts/math.ts +62 -0
- package/src/ts/numRange.ts +15 -0
- package/src/ts.ts +54 -0
- package/tsconfig.json +22 -0
- package/conv.d.ts +0 -28
- package/conv.d.ts.map +0 -1
- package/conv.js.map +0 -1
- package/elastic.d.ts +0 -54
- package/elastic.d.ts.map +0 -1
- package/elastic.js +0 -150
- package/elastic.js.map +0 -1
- package/geo.d.ts +0 -19
- package/geo.d.ts.map +0 -1
- package/geo.js +0 -32
- package/geo.js.map +0 -1
- package/index.d.ts +0 -10
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/logic.d.ts +0 -23
- package/logic.d.ts.map +0 -1
- package/logic.js +0 -50
- package/logic.js.map +0 -1
- package/math.d.ts +0 -35
- package/math.d.ts.map +0 -1
- package/math.js.map +0 -1
- package/object.d.ts +0 -169
- package/object.d.ts.map +0 -1
- package/object.js +0 -349
- package/object.js.map +0 -1
- package/react.d.ts +0 -2
- package/react.d.ts.map +0 -1
- package/react.js +0 -14
- package/react.js.map +0 -1
- package/test/matchers.d.ts +0 -15
- package/test/matchers.d.ts.map +0 -1
- package/test/matchers.js +0 -69
- package/test/matchers.js.map +0 -1
- package/test.d.ts +0 -14
- package/test.d.ts.map +0 -1
- package/test.js +0 -2
- package/test.js.map +0 -1
- package/ts/math.d.ts +0 -12
- package/ts/math.d.ts.map +0 -1
- package/ts/math.js +0 -2
- package/ts/math.js.map +0 -1
- package/ts/numRange.d.ts +0 -12
- package/ts/numRange.d.ts.map +0 -1
- package/ts/numRange.js +0 -2
- package/ts/numRange.js.map +0 -1
- package/ts.d.ts +0 -29
- package/ts.d.ts.map +0 -1
- package/ts.js +0 -6
- package/ts.js.map +0 -1
package/elastic.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Client, SearchParams, SearchResponse, IndicesCreateParams } from "elasticsearch";
|
|
2
|
-
import type { UnknownRecord } from "./ts.js";
|
|
3
|
-
import { EventEmitter } from "events";
|
|
4
|
-
/**
|
|
5
|
-
* Indexes a large amount of entities in a single query
|
|
6
|
-
* @param entities Array containing entities to index
|
|
7
|
-
* @param indexName Name of index to index entities.
|
|
8
|
-
*
|
|
9
|
-
* @returns Promise that resolves time taken to index entities in ms.
|
|
10
|
-
*/
|
|
11
|
-
export declare const bulkIndex: (elastic: Client, entities: UnknownRecord[], indexName: string, refresh?: boolean) => Promise<number>;
|
|
12
|
-
/**
|
|
13
|
-
* Queries elastic using `params`.
|
|
14
|
-
* @param params Query object.
|
|
15
|
-
*
|
|
16
|
-
* @returns Iterator that yeilds a result until query exhausted.
|
|
17
|
-
*/
|
|
18
|
-
export declare function scrollSearch(elastic: Client, params: SearchParams): AsyncGenerator<SearchResponse<unknown>>;
|
|
19
|
-
/**
|
|
20
|
-
* Function to recreate a elasticsearch index.
|
|
21
|
-
* @param elastic Elasticsearch client
|
|
22
|
-
* @param createParams Elastic parameters for creation of index
|
|
23
|
-
* @param options Options for creation
|
|
24
|
-
*/
|
|
25
|
-
export declare const createIndex: (elastic: Client, createParams: IndicesCreateParams, options: {
|
|
26
|
-
logProgress?: boolean;
|
|
27
|
-
destoryIfExists: boolean;
|
|
28
|
-
}) => Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Returns scrollsearch results in simulated time based on when result timestamp.
|
|
31
|
-
* @param elastic Elasticsearch client to use
|
|
32
|
-
* @param query Query object to use for scroll search
|
|
33
|
-
* @param timestampKey Key to use for fetching timestamp from objects
|
|
34
|
-
* @param options.timescale Rate at which "time" progreesses
|
|
35
|
-
* @returns EventEmitter which emits 'entity' events containing resulting hits
|
|
36
|
-
* @example
|
|
37
|
-
* const elasticClient = new ElasticClient({ node: 'http://127.0.0.1:9200' })
|
|
38
|
-
* const timestamp = "reportedTime"
|
|
39
|
-
* const query = {
|
|
40
|
-
* index: "documents_index",
|
|
41
|
-
* scroll: '10m',
|
|
42
|
-
* body: {
|
|
43
|
-
* "query": { "match_all": {} },
|
|
44
|
-
* "sort": [{ [timestamp]: {"order": "asc"} }],
|
|
45
|
-
* "size": 10000
|
|
46
|
-
* }
|
|
47
|
-
* }
|
|
48
|
-
* stream(elasticClient, query, timestamp, 2).on('entity', console.log) // <- Emitted results based on time moving at 2x normal speed
|
|
49
|
-
*/
|
|
50
|
-
export declare const stream: (elastic: Client, query: SearchParams, timestampKey: string, options?: {
|
|
51
|
-
timescale: number;
|
|
52
|
-
logProgress: boolean;
|
|
53
|
-
}) => EventEmitter;
|
|
54
|
-
//# sourceMappingURL=elastic.d.ts.map
|
package/elastic.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elastic.d.ts","sourceRoot":"","sources":["../src/elastic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,YAAmB,MAAM,YAAY,aAAa,EAAE,aAAa,MAAM,wBAAoB,QAAQ,MAAM,CAI5H,CAAC;AAEJ;;;;;GAKG;AACH,wBAAuB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAelH;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,YACd,MAAM,gBACD,mBAAmB,WACxB;IAAE,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,KAC1D,QAAQ,IAAI,CAoCd,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,MAAM,YACT,MAAM,SACR,YAAY,gBACL,MAAM,YACX;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,KAClD,YA0BF,CAAC"}
|
package/elastic.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
/**
|
|
3
|
-
* Indexes a large amount of entities in a single query
|
|
4
|
-
* @param entities Array containing entities to index
|
|
5
|
-
* @param indexName Name of index to index entities.
|
|
6
|
-
*
|
|
7
|
-
* @returns Promise that resolves time taken to index entities in ms.
|
|
8
|
-
*/
|
|
9
|
-
export const bulkIndex = async (elastic, entities, indexName, refresh = false) => elastic.bulk({
|
|
10
|
-
refresh: refresh,
|
|
11
|
-
body: entities.flatMap((entity) => [{ index: { _index: indexName } }, entity]),
|
|
12
|
-
});
|
|
13
|
-
/**
|
|
14
|
-
* Queries elastic using `params`.
|
|
15
|
-
* @param params Query object.
|
|
16
|
-
*
|
|
17
|
-
* @returns Iterator that yeilds a result until query exhausted.
|
|
18
|
-
*/
|
|
19
|
-
export async function* scrollSearch(elastic, params) {
|
|
20
|
-
if (params.scroll === undefined)
|
|
21
|
-
throw new Error("params.scroll is required!");
|
|
22
|
-
let response = await elastic.search(params);
|
|
23
|
-
let nextResponse;
|
|
24
|
-
while (true) {
|
|
25
|
-
nextResponse = elastic.scroll({
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
27
|
-
scrollId: response._scroll_id,
|
|
28
|
-
scroll: params.scroll,
|
|
29
|
-
});
|
|
30
|
-
if (!response._scroll_id)
|
|
31
|
-
break;
|
|
32
|
-
if (response.hits.hits.length === 0)
|
|
33
|
-
break;
|
|
34
|
-
yield response;
|
|
35
|
-
response = await nextResponse;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Function to recreate a elasticsearch index.
|
|
40
|
-
* @param elastic Elasticsearch client
|
|
41
|
-
* @param createParams Elastic parameters for creation of index
|
|
42
|
-
* @param options Options for creation
|
|
43
|
-
*/
|
|
44
|
-
export const createIndex = async (elastic, createParams, options) => {
|
|
45
|
-
if (!options)
|
|
46
|
-
throw new Error("Options required!");
|
|
47
|
-
if (!createParams)
|
|
48
|
-
throw new Error("Elastic parameters required! (createParams)");
|
|
49
|
-
if (!options.logProgress)
|
|
50
|
-
options.logProgress = false;
|
|
51
|
-
if (options.destoryIfExists) {
|
|
52
|
-
try {
|
|
53
|
-
await elastic.indices.exists({ index: createParams.index });
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
if (err instanceof Error)
|
|
57
|
-
err.message = "Failed to check if old index exists!\n" + err.message;
|
|
58
|
-
throw err;
|
|
59
|
-
}
|
|
60
|
-
if (options.logProgress)
|
|
61
|
-
process.stdout.write(`Deleting index "${createParams.index}"...`);
|
|
62
|
-
try {
|
|
63
|
-
await elastic.indices.delete({ index: createParams.index });
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
if (err instanceof Error)
|
|
67
|
-
err.message = "Failed to delete old index!\n" + err.message;
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
if (options.logProgress)
|
|
71
|
-
process.stdout.write(` Deleted!\nCreating index "${createParams.index}"...`);
|
|
72
|
-
try {
|
|
73
|
-
await elastic.indices.create(createParams);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
if (err instanceof Error)
|
|
77
|
-
err.message = "Failed to create new index!\n" + err.message;
|
|
78
|
-
throw err;
|
|
79
|
-
}
|
|
80
|
-
if (options.logProgress)
|
|
81
|
-
process.stdout.write(" Created!\n");
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (options.logProgress)
|
|
85
|
-
process.stdout.write(`Creating index "${createParams.index}"...`);
|
|
86
|
-
try {
|
|
87
|
-
await elastic.indices.create(createParams);
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
if (err instanceof Error)
|
|
91
|
-
err.message = "Failed to create new index!\n" + err.message;
|
|
92
|
-
throw err;
|
|
93
|
-
}
|
|
94
|
-
if (options.logProgress)
|
|
95
|
-
process.stdout.write(" Created!\n");
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Returns scrollsearch results in simulated time based on when result timestamp.
|
|
100
|
-
* @param elastic Elasticsearch client to use
|
|
101
|
-
* @param query Query object to use for scroll search
|
|
102
|
-
* @param timestampKey Key to use for fetching timestamp from objects
|
|
103
|
-
* @param options.timescale Rate at which "time" progreesses
|
|
104
|
-
* @returns EventEmitter which emits 'entity' events containing resulting hits
|
|
105
|
-
* @example
|
|
106
|
-
* const elasticClient = new ElasticClient({ node: 'http://127.0.0.1:9200' })
|
|
107
|
-
* const timestamp = "reportedTime"
|
|
108
|
-
* const query = {
|
|
109
|
-
* index: "documents_index",
|
|
110
|
-
* scroll: '10m',
|
|
111
|
-
* body: {
|
|
112
|
-
* "query": { "match_all": {} },
|
|
113
|
-
* "sort": [{ [timestamp]: {"order": "asc"} }],
|
|
114
|
-
* "size": 10000
|
|
115
|
-
* }
|
|
116
|
-
* }
|
|
117
|
-
* stream(elasticClient, query, timestamp, 2).on('entity', console.log) // <- Emitted results based on time moving at 2x normal speed
|
|
118
|
-
*/
|
|
119
|
-
export const stream = (elastic, query, timestampKey, options = { timescale: 1, logProgress: false }) => {
|
|
120
|
-
const entityReceiver = new EventEmitter();
|
|
121
|
-
(async () => {
|
|
122
|
-
if (options.timescale === undefined)
|
|
123
|
-
options.timescale = 1;
|
|
124
|
-
if (typeof options.timescale !== "number")
|
|
125
|
-
throw new Error("options.timescale must be a number!");
|
|
126
|
-
if (timestampKey === undefined)
|
|
127
|
-
throw new Error("timestampKey is undefined!");
|
|
128
|
-
let timeOffset;
|
|
129
|
-
let startDate = Date.now();
|
|
130
|
-
if (options.logProgress)
|
|
131
|
-
console.log("Beginning elastic scroll for entity streaming...");
|
|
132
|
-
for await (const result of scrollSearch(elastic, query)) {
|
|
133
|
-
if (options.logProgress)
|
|
134
|
-
console.log(`Query iteration finished, streaming ${result.hits.hits.length} entities.`);
|
|
135
|
-
if (timeOffset === undefined) {
|
|
136
|
-
timeOffset = Date.now() - new Date(result.hits.hits[0]._source[timestampKey]).getTime();
|
|
137
|
-
startDate = Date.now();
|
|
138
|
-
}
|
|
139
|
-
for (const entity of result.hits.hits) {
|
|
140
|
-
const offsetEntityTime = new Date(entity._source[timestampKey]).getTime() + timeOffset;
|
|
141
|
-
while (Date.now() + (Date.now() - startDate) * options.timescale < offsetEntityTime) {
|
|
142
|
-
// Spin while waiting to emit next entity
|
|
143
|
-
}
|
|
144
|
-
entityReceiver.emit("entity", entity._source);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
})();
|
|
148
|
-
return entityReceiver;
|
|
149
|
-
};
|
|
150
|
-
//# sourceMappingURL=elastic.js.map
|
package/elastic.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elastic.js","sourceRoot":"","sources":["../src/elastic.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,OAAe,EAAE,QAAyB,EAAE,SAAiB,EAAE,OAAO,GAAG,KAAK,EAAmB,EAAE,CAClI,OAAO,CAAC,IAAI,CAAC;IACZ,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EA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GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;gBACxF,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;aACvB;YACD,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;gBACtC,MAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC;gBACvF,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,GAAG,gBAAgB,EAAE;oBACpF,yCAAyC;iBACzC;gBACD,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;aAC9C;SACD;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,cAAc,CAAC;AACvB,CAAC,CAAC"}
|
package/geo.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts latitude or longitude to degrees, minutes & seconds.
|
|
3
|
-
* @param coord Latitude or longitude coordinate
|
|
4
|
-
*
|
|
5
|
-
* @returns Coordinate in degrees, minutes & seconds
|
|
6
|
-
*/
|
|
7
|
-
export declare const toDMS: (coord: number) => {
|
|
8
|
-
degrees: number;
|
|
9
|
-
minutes: number;
|
|
10
|
-
seconds: number;
|
|
11
|
-
};
|
|
12
|
-
export declare const toRad: (val: number) => number;
|
|
13
|
-
/**
|
|
14
|
-
* Returns the distance between two LatLong's in kilometers
|
|
15
|
-
* @param pos1 [lat, long] coordinates
|
|
16
|
-
* @param pos2 [lat, long] coordinates
|
|
17
|
-
*/
|
|
18
|
-
export declare const getDistance: (pos1: [number, number], pos2: [number, number]) => number;
|
|
19
|
-
//# sourceMappingURL=geo.d.ts.map
|
package/geo.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geo.d.ts","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM;aAAc,MAAM;aAAW,MAAM;aAAW,MAAM;CAOxF,CAAC;AAGF,eAAO,MAAM,KAAK,QAAS,MAAM,KAAG,MAA+B,CAAC;AAEpE;;;;GAIG;AACH,eAAO,MAAM,WAAW,SAAU,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAG,MAS5E,CAAC"}
|
package/geo.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts latitude or longitude to degrees, minutes & seconds.
|
|
3
|
-
* @param coord Latitude or longitude coordinate
|
|
4
|
-
*
|
|
5
|
-
* @returns Coordinate in degrees, minutes & seconds
|
|
6
|
-
*/
|
|
7
|
-
export const toDMS = (coord) => {
|
|
8
|
-
const absolute = Math.abs(coord);
|
|
9
|
-
const degrees = Math.floor(absolute);
|
|
10
|
-
const minutesNotTruncated = (absolute - degrees) * 60;
|
|
11
|
-
const minutes = Math.floor(minutesNotTruncated);
|
|
12
|
-
const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
|
|
13
|
-
return { degrees, minutes, seconds };
|
|
14
|
-
};
|
|
15
|
-
// Converts numeric degrees to radians
|
|
16
|
-
export const toRad = (val) => (val * Math.PI) / 180;
|
|
17
|
-
/**
|
|
18
|
-
* Returns the distance between two LatLong's in kilometers
|
|
19
|
-
* @param pos1 [lat, long] coordinates
|
|
20
|
-
* @param pos2 [lat, long] coordinates
|
|
21
|
-
*/
|
|
22
|
-
export const getDistance = (pos1, pos2) => {
|
|
23
|
-
const [lat1, lon1] = pos1;
|
|
24
|
-
const [lat2, lon2] = pos2;
|
|
25
|
-
const R = 6371; // km
|
|
26
|
-
const dLat = toRad(lat2 - lat1);
|
|
27
|
-
const dLon = toRad(lon2 - lon1);
|
|
28
|
-
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(toRad(lat1)) * Math.cos(toRad(lat2));
|
|
29
|
-
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
30
|
-
return R * c;
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=geo.js.map
|
package/geo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../src/geo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAyD,EAAE;IAC7F,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,mBAAmB,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF,sCAAsC;AACtC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;AAEpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAsB,EAAE,IAAsB,EAAU,EAAE;IACrF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK;IACrB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5I,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzD,OAAO,CAAC,GAAG,CAAC,CAAC;AACd,CAAC,CAAC"}
|
package/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./conv.js";
|
|
2
|
-
export * from "./elastic.js";
|
|
3
|
-
export * from "./geo.js";
|
|
4
|
-
export * from "./logic.js";
|
|
5
|
-
export * from "./math.js";
|
|
6
|
-
export * from "./object.js";
|
|
7
|
-
export * from "./react.js";
|
|
8
|
-
export * from "./test.js";
|
|
9
|
-
export * from "./ts.js";
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/logic.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
export declare const sleep: typeof import("timers/promises").setTimeout;
|
|
3
|
-
export declare class Promize<T> {
|
|
4
|
-
p: Promise<T>;
|
|
5
|
-
res: (value: T) => void;
|
|
6
|
-
rej: (reason?: any) => void;
|
|
7
|
-
/**
|
|
8
|
-
* Returns a new instance of a `Promize`, a externally resolvable Promise.
|
|
9
|
-
* @param resValue If not undefined, resolves the internal promise with given value on creation.
|
|
10
|
-
*/
|
|
11
|
-
constructor(resValue?: T);
|
|
12
|
-
/**
|
|
13
|
-
* Recreate the promise
|
|
14
|
-
* @param resValue If not undefined, resolves the internal promise with given value on creation.
|
|
15
|
-
*/
|
|
16
|
-
set(resValue?: T): void;
|
|
17
|
-
}
|
|
18
|
-
export declare const retry: <T>(func: () => T | Promise<T>, options?: {
|
|
19
|
-
onErr?: ((error: unknown, retryCount: number) => void) | undefined;
|
|
20
|
-
timeoutMultiplier?: number | undefined;
|
|
21
|
-
maxRetries?: number | undefined;
|
|
22
|
-
} | undefined) => () => Promise<T>;
|
|
23
|
-
//# sourceMappingURL=logic.d.ts.map
|
package/logic.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":";AACA,eAAO,MAAM,KAAK,6CAAwB,CAAC;AAE3C,qBAAa,OAAO,CAAC,CAAC;IACd,CAAC,EAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,GAAG,EAAG,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACzB,GAAG,EAAG,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAE7B;;;OAGG;gBACS,QAAQ,CAAC,EAAE,CAAC;IAIxB;;;OAGG;IACH,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI;CAOvB;AAED,eAAO,MAAM,KAAK;qBAEW,OAAO,cAAc,MAAM,KAAK,IAAI;;;kCAoBhE,CAAC"}
|
package/logic.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { promisify } from "util";
|
|
2
|
-
export const sleep = promisify(setTimeout);
|
|
3
|
-
export class Promize {
|
|
4
|
-
p;
|
|
5
|
-
res;
|
|
6
|
-
rej;
|
|
7
|
-
/**
|
|
8
|
-
* Returns a new instance of a `Promize`, a externally resolvable Promise.
|
|
9
|
-
* @param resValue If not undefined, resolves the internal promise with given value on creation.
|
|
10
|
-
*/
|
|
11
|
-
constructor(resValue) {
|
|
12
|
-
this.set(resValue);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Recreate the promise
|
|
16
|
-
* @param resValue If not undefined, resolves the internal promise with given value on creation.
|
|
17
|
-
*/
|
|
18
|
-
set(resValue) {
|
|
19
|
-
this.p = new Promise((res, rej) => {
|
|
20
|
-
this.res = res;
|
|
21
|
-
this.rej = rej;
|
|
22
|
-
});
|
|
23
|
-
if (resValue !== undefined)
|
|
24
|
-
this.res(resValue);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export const retry = (func, options) => {
|
|
28
|
-
let retryCount = 0;
|
|
29
|
-
const maxRetries = options?.maxRetries ?? 10;
|
|
30
|
-
const timeoutMultiplier = options?.timeoutMultiplier ?? 1000;
|
|
31
|
-
const onErr = options?.onErr;
|
|
32
|
-
const tryAgain = async () => {
|
|
33
|
-
try {
|
|
34
|
-
return await func();
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
if (onErr !== undefined)
|
|
38
|
-
onErr(e, retryCount);
|
|
39
|
-
if (retryCount < maxRetries) {
|
|
40
|
-
retryCount++;
|
|
41
|
-
if (timeoutMultiplier > 0)
|
|
42
|
-
await sleep(Math.random() * timeoutMultiplier);
|
|
43
|
-
return tryAgain();
|
|
44
|
-
}
|
|
45
|
-
throw e;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
return tryAgain;
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=logic.js.map
|
package/logic.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logic.js","sourceRoot":"","sources":["../src/logic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;AAE3C,MAAM,OAAO,OAAO;IACZ,CAAC,CAAc;IACtB,GAAG,CAAsB;IACzB,GAAG,CAA0B;IAE7B;;;OAGG;IACH,YAAY,QAAY;QACvB,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,QAAY;QACf,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;YACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;CACD;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CACpB,IAA0B,EAC1B,OAAmH,EAC9F,EAAE;IACvB,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC;IAC7C,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI,IAAI,CAAC;IAC7D,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAC7B,MAAM,QAAQ,GAAG,KAAK,IAAgB,EAAE;QACvC,IAAI;YACH,OAAO,MAAM,IAAI,EAAE,CAAC;SACpB;QAAC,OAAO,CAAC,EAAE;YACX,IAAI,KAAK,KAAK,SAAS;gBAAE,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;YAC9C,IAAI,UAAU,GAAG,UAAU,EAAE;gBAC5B,UAAU,EAAE,CAAC;gBACb,IAAI,iBAAiB,GAAG,CAAC;oBAAE,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,iBAAiB,CAAC,CAAC;gBAC1E,OAAO,QAAQ,EAAE,CAAC;aAClB;YACD,MAAM,CAAC,CAAC;SACR;IACF,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC"}
|
package/math.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates the difference between two angles (0°-360°), `angle1` & `angle2` returned result is in decimal degrees and is signed.
|
|
3
|
-
* @param angle1 First angle to compare
|
|
4
|
-
* @param angle2 Second angle to compare
|
|
5
|
-
* @param signed If the result is signed or absolute
|
|
6
|
-
* @returns The difference in degrees
|
|
7
|
-
*/
|
|
8
|
-
export declare const angleDifference: (angle1: number, angle2: number, signed?: boolean) => number;
|
|
9
|
-
/**
|
|
10
|
-
* Converts `angle` to 0°-360°
|
|
11
|
-
* @param angle
|
|
12
|
-
* @returns `angle` in 0-360°
|
|
13
|
-
*/
|
|
14
|
-
export declare const to360: (angle: number) => number;
|
|
15
|
-
/**
|
|
16
|
-
* Rounds a number to `digits` decimal places.
|
|
17
|
-
* @param num Number to round
|
|
18
|
-
* @param digits Decimal places to round to
|
|
19
|
-
* @returns Rounded number
|
|
20
|
-
*/
|
|
21
|
-
export declare const qRnd: (num: number, digits?: number) => number;
|
|
22
|
-
/**
|
|
23
|
-
* Pad a number with 0's
|
|
24
|
-
* @param num Number to pad.
|
|
25
|
-
* @param zeros Number of digits returned number should have.
|
|
26
|
-
*
|
|
27
|
-
* @returns Padded number
|
|
28
|
-
* @example
|
|
29
|
-
* let paddedNumber = nPad(5)
|
|
30
|
-
* // paddedNumber = "05"
|
|
31
|
-
* let triplePaddedNumber = nPad(6, 3)
|
|
32
|
-
* // triplePaddedNumber = "006"
|
|
33
|
-
*/
|
|
34
|
-
export declare const nPad: (num: number | string, zeros?: number) => string;
|
|
35
|
-
//# sourceMappingURL=math.d.ts.map
|
package/math.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,UAAU,MAAM,uBAAkB,MAO/E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,MAGrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,sBAAe,MAG9C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,QAAS,MAAM,GAAG,MAAM,qBAAc,MAItD,CAAC"}
|
package/math.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-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oB,EAAE,KAAK,GAAG,CAAC,EAAU,EAAE;IAC/D,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACrB,OAAO,GAAG,CAAC,MAAM,GAAG,KAAK;QAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IAC3C,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
|
package/object.d.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { UnknownRecord } from "./ts.js";
|
|
2
|
-
export declare const isDuplicate: (key: unknown) => boolean;
|
|
3
|
-
/**
|
|
4
|
-
* Simple object check.
|
|
5
|
-
* @param item
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
export declare const isObject: (item: unknown) => item is UnknownRecord;
|
|
9
|
-
/**
|
|
10
|
-
* Deep merge objects into target. Without modifying target.
|
|
11
|
-
* @param target
|
|
12
|
-
* @param source
|
|
13
|
-
*/
|
|
14
|
-
export declare const deepMerge: <T extends S, S extends UnknownRecord = Partial<T>>(target: T, source: S) => T & S;
|
|
15
|
-
export declare type Types = {
|
|
16
|
-
[key: string]: string | string[] | Types | Types[];
|
|
17
|
-
};
|
|
18
|
-
export declare type TypeCompareResult = boolean | {
|
|
19
|
-
expectedType: string;
|
|
20
|
-
received: string;
|
|
21
|
-
location: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Take in a target `object` and a `types` object with identical keys but values as array of types those keys should be.
|
|
25
|
-
* @param target Object
|
|
26
|
-
* @param types Object identical to `target` but values are types
|
|
27
|
-
* @returns `object` if the types dont match. `True` if they do.
|
|
28
|
-
*/
|
|
29
|
-
export declare const deepTypeCompare: (target: UnknownRecord, types: Types, location?: string) => TypeCompareResult;
|
|
30
|
-
/**
|
|
31
|
-
* Helper function for `deepTypeCompare` to compare a item to a type or set of types.
|
|
32
|
-
* @param expectedTypes Expected type/types
|
|
33
|
-
* @param receivedValue Object given
|
|
34
|
-
* @param location Location of `got` given
|
|
35
|
-
*/
|
|
36
|
-
export declare const compareTwo: (expectedTypes: string | string[], receivedValue: unknown, location: string) => TypeCompareResult;
|
|
37
|
-
/**
|
|
38
|
-
* Returns the type of `item` respecting `Array`, `null` and `undefined` unlike typeof.
|
|
39
|
-
* @param item
|
|
40
|
-
* @returns Type of item
|
|
41
|
-
*/
|
|
42
|
-
export declare const type: (item: unknown) => string;
|
|
43
|
-
/**
|
|
44
|
-
* Breaks `array` into smaller chunks based on `chunkSize`
|
|
45
|
-
* @param array Array to break up.
|
|
46
|
-
* @param chunkSize Maximum size of array chunks.
|
|
47
|
-
*
|
|
48
|
-
* @returns Array containing array chunks.
|
|
49
|
-
*/
|
|
50
|
-
export declare const chunkArray: <T extends string | unknown[]>(array: T, chunkSize: number) => T[];
|
|
51
|
-
/**
|
|
52
|
-
* stringifies and then parses a object to convert it to a JSON supported object.
|
|
53
|
-
* @param obj Object to convert.
|
|
54
|
-
* @example
|
|
55
|
-
* const obj = {
|
|
56
|
-
* a: 1,
|
|
57
|
-
* b: [2, 7]
|
|
58
|
-
* }
|
|
59
|
-
* const a = objectify(obj)
|
|
60
|
-
* const b = JSON.parse(JSON.stringify(obj))
|
|
61
|
-
* console.log(a == b) -> true
|
|
62
|
-
*/
|
|
63
|
-
export declare const objectify: (obj: UnknownRecord) => UnknownRecord;
|
|
64
|
-
/**
|
|
65
|
-
* Logs a inspected object to console
|
|
66
|
-
* @param obj Object to inspect
|
|
67
|
-
* @param options.showHidden Show hidden properties of object
|
|
68
|
-
* @param options.depth Depth to inspect object
|
|
69
|
-
* @param options.color Color resulting output
|
|
70
|
-
*/
|
|
71
|
-
export declare const lObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => void;
|
|
72
|
-
/**
|
|
73
|
-
* Inspects a object
|
|
74
|
-
* @param obj Object to inspect
|
|
75
|
-
* @param options.showHidden Show hidden properties of object
|
|
76
|
-
* @param options.depth Depth to inspect object
|
|
77
|
-
* @param options.color Color resulting output
|
|
78
|
-
*/
|
|
79
|
-
export declare const iObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => string;
|
|
80
|
-
/**
|
|
81
|
-
* Single line inspect object.
|
|
82
|
-
* @param obj Object to inspect
|
|
83
|
-
* @param options.showHidden Show hidden properties of object
|
|
84
|
-
* @param options.depth Depth to inspect object
|
|
85
|
-
* @param options.color Color resulting output
|
|
86
|
-
*/
|
|
87
|
-
export declare const sliObj: (obj: unknown, showHidden?: boolean | undefined, depth?: number | undefined, color?: boolean | undefined) => string;
|
|
88
|
-
declare type AsyncFunction = (...args: unknown[]) => Promise<unknown>;
|
|
89
|
-
declare type ErrorHandler = (err: Error) => Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Recursively runs `func` and handles errors with `errorHandler` until `func` successfully finishes.
|
|
92
|
-
* @param func Function to execute
|
|
93
|
-
* @param errorHandler Function to execute when a error occours
|
|
94
|
-
* @returns Return value of `func` on success
|
|
95
|
-
*/
|
|
96
|
-
export declare const loopError: <F extends AsyncFunction>(func: F, errorHandler?: ErrorHandler) => ReturnType<F>;
|
|
97
|
-
/**
|
|
98
|
-
* @param array
|
|
99
|
-
* @returns string containing ranges of numbers.
|
|
100
|
-
* @example
|
|
101
|
-
* const range = toRange([1, 2, 3, 12, 6,7, 5, 27, 28, 29, 40, 41, 25, 42, 12])
|
|
102
|
-
* // range = "1-3 & 5-7 & 12 & 25 & 27-29 & 40-42"
|
|
103
|
-
*/
|
|
104
|
-
export declare const toRange: (array: number[]) => string;
|
|
105
|
-
/**
|
|
106
|
-
* Returns the `property` requested from `obj`
|
|
107
|
-
* @param obj
|
|
108
|
-
* @param property
|
|
109
|
-
* @param delimiter
|
|
110
|
-
* @example
|
|
111
|
-
* const object = {
|
|
112
|
-
* a: {
|
|
113
|
-
* child: "Hello World"
|
|
114
|
-
* }
|
|
115
|
-
* }
|
|
116
|
-
* const wantedProperty = "a.child"
|
|
117
|
-
* console.log(deepGet(object, wantedProperty)) // -> "Hello World"
|
|
118
|
-
*/
|
|
119
|
-
export declare const deepGet: <T = unknown>(obj: UnknownRecord, property: string, delimiter?: string) => T | undefined;
|
|
120
|
-
declare type ContentTemplate = {
|
|
121
|
-
[key: string]: string | ContentTemplate;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* Replaces values in a given `templatestring` with contentKeys from a given `contentKeys` object.
|
|
125
|
-
* @param contentKeys Object containing key value pairs of contentKeys to fill template string with
|
|
126
|
-
* @param templatestring string containing templates to fill
|
|
127
|
-
* @example
|
|
128
|
-
* const contentKeys = {
|
|
129
|
-
* "title": "This is a title",
|
|
130
|
-
* "info": {
|
|
131
|
-
* "desc": "This is some info!"
|
|
132
|
-
* }
|
|
133
|
-
* }
|
|
134
|
-
* const template = "Wow! {title}... Here is some info: {info.desc}"
|
|
135
|
-
*
|
|
136
|
-
* fillTemplate(contentKeys, template) // => Wow! This is a title... Here is some info: This is some info!"
|
|
137
|
-
*/
|
|
138
|
-
export declare const fillTemplate: (contentKeys: ContentTemplate, templatestring: string, parent?: string) => string;
|
|
139
|
-
declare type EnvDict = {
|
|
140
|
-
[key: string]: string | EnvDict;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Converts process.env variables into a object
|
|
144
|
-
* @example process.env["some_subproperty"] = "hello"
|
|
145
|
-
* returns { some: { subProperty: "hello" } }
|
|
146
|
-
*/
|
|
147
|
-
export declare const getEnv: () => EnvDict;
|
|
148
|
-
declare type RecursiveUpdateOptions = {
|
|
149
|
-
setUndefined?: boolean;
|
|
150
|
-
setDefined?: boolean;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Recursively update properties of a object with another.
|
|
154
|
-
* @param targetObject Object to update.
|
|
155
|
-
* @param newObject Object with new values to write to `targetObject`.
|
|
156
|
-
* @param options.setUndefined Defaults to `true` Set properties that are undefined on `targetObject`.
|
|
157
|
-
* @param options.setDefined Defaults to `false`. Overwrite properties that are not undefined on `targetObject`.
|
|
158
|
-
*/
|
|
159
|
-
export declare const recursiveUpdate: (targetObject: UnknownRecord, newObject: UnknownRecord, options?: RecursiveUpdateOptions) => void;
|
|
160
|
-
/**
|
|
161
|
-
* Set the types of a given `object` based on the types of an identical `types` object. Usful in conjunction with `getEnv` to convert a object only containing strings/objects to actual types.
|
|
162
|
-
*/
|
|
163
|
-
export declare const rebuildTypes: (object: UnknownRecord, types: UnknownRecord) => void;
|
|
164
|
-
/**
|
|
165
|
-
* Fetch process.env[envName] or throw if its undefined
|
|
166
|
-
*/
|
|
167
|
-
export declare const envOrThrow: (envName: string) => string;
|
|
168
|
-
export {};
|
|
169
|
-
//# sourceMappingURL=object.d.ts.map
|
package/object.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxC,eAAO,MAAM,WAAW,QAAS,OAAO,KAAG,OAI1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAAU,OAAO,0BAAkG,CAAC;AAEzI;;;;GAIG;AACH,eAAO,MAAM,SAAS,oFAWrB,CAAC;AAEF,oBAAY,KAAK,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,KAAK,EAAE,CAAA;CAAE,CAAC;AAC3E,oBAAY,iBAAiB,GAAG,OAAO,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvG;;;;;GAKG;AACH,eAAO,MAAM,eAAe,WAAY,aAAa,SAAS,KAAK,wBAAwB,iBA0B1F,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,kBAAmB,MAAM,GAAG,MAAM,EAAE,iBAAiB,OAAO,YAAY,MAAM,KAAG,iBAOv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