@candlerip/shared3 0.0.97 → 0.0.98
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/type/array/index.d.ts +1 -0
- package/src/type/array/index.js +1 -0
- package/src/type/array/validate.d.ts +6 -0
- package/src/type/array/validate.js +16 -0
- package/src/type/string/index.d.ts +1 -0
- package/src/type/string/index.js +1 -0
- package/src/type/string/validate-comma-separated-string/index.d.ts +2 -0
- package/src/type/string/validate-comma-separated-string/index.js +17 -0
- package/src/type/string/validate-comma-separated-string/types.d.ts +6 -0
- package/src/type/string/validate-comma-separated-string/types.js +1 -0
package/package.json
CHANGED
package/src/type/array/index.js
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { customErrorWorker } from '../../error/index.js';
|
2
|
+
export const validateArray = (data, name, valid) => {
|
3
|
+
const { composeCustomError } = customErrorWorker({ data, name, valid });
|
4
|
+
if (!data) {
|
5
|
+
return composeCustomError(`Missing ${name}`);
|
6
|
+
}
|
7
|
+
if (!Array.isArray(data)) {
|
8
|
+
return composeCustomError(`Invalid ${name}`);
|
9
|
+
}
|
10
|
+
if (!data.every((it) => valid.includes(it))) {
|
11
|
+
return composeCustomError(`Invalid ${name}`);
|
12
|
+
}
|
13
|
+
return {
|
14
|
+
data,
|
15
|
+
};
|
16
|
+
};
|
package/src/type/string/index.js
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
import { customErrorWorker } from '../../../error/index.js';
|
2
|
+
import { validateArray } from '../../array/index.js';
|
3
|
+
import { isString } from '../type-guard.js';
|
4
|
+
export const validateCommaSeparatedString = (data, name, valid) => {
|
5
|
+
const { composeCustomError } = customErrorWorker({ data, name, valid });
|
6
|
+
if (!data) {
|
7
|
+
return composeCustomError(`Missing ${name}`);
|
8
|
+
}
|
9
|
+
if (!isString(data)) {
|
10
|
+
return composeCustomError(`${name} not string`);
|
11
|
+
}
|
12
|
+
const parsedArr = data.split(',');
|
13
|
+
if (parsedArr.length === 0) {
|
14
|
+
return composeCustomError(`Invalid ${name}`);
|
15
|
+
}
|
16
|
+
return validateArray(parsedArr, name, valid);
|
17
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|