@xsai/shared 0.1.0-beta.2 → 0.1.0-beta.4
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/dist/index.d.ts +17 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,23 @@ declare const objCamelToSnake: (obj: Record<string, unknown>) => {
|
|
|
20
20
|
[k: string]: unknown;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Clean all undefined values.
|
|
25
|
+
* @param obj object
|
|
26
|
+
* @returns cleaned object
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { clean } from '@xsai/shared'
|
|
31
|
+
*
|
|
32
|
+
* // { a: 'a' }
|
|
33
|
+
* const obj = clean({
|
|
34
|
+
* a: 'a',
|
|
35
|
+
* b: undefined
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const clean: <T extends Record<string, undefined | unknown>>(obj: T) => Record<keyof T, Exclude<T[keyof T], unknown>>;
|
|
24
40
|
|
|
25
41
|
declare const requestBody: (body: Record<string, unknown>) => string;
|
|
26
42
|
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,9 @@ class XSAIError extends Error {
|
|
|
10
10
|
const strCamelToSnake = (str) => str.replace(/[A-Z]/g, (s) => `_${s.toLowerCase()}`);
|
|
11
11
|
const objCamelToSnake = (obj) => Object.fromEntries(Object.entries(obj).map(([k, v]) => [strCamelToSnake(k), v]));
|
|
12
12
|
|
|
13
|
-
const clean = (
|
|
13
|
+
const clean = (obj) => Object.fromEntries(
|
|
14
|
+
Object.entries(obj).filter(([, v]) => v !== undefined)
|
|
15
|
+
);
|
|
14
16
|
|
|
15
17
|
const requestBody = (body) => JSON.stringify(objCamelToSnake(clean({
|
|
16
18
|
...body,
|
package/package.json
CHANGED