@oscarpalmer/jhunal 0.13.0 → 0.15.0
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/constants.js +5 -6
- package/dist/helpers.js +11 -0
- package/dist/index.js +2 -2
- package/dist/jhunal.full.js +42 -12
- package/dist/models.js +8 -0
- package/dist/schematic.js +2 -0
- package/dist/validation/property.validation.js +18 -10
- package/package.json +1 -1
- package/src/constants.ts +7 -9
- package/src/helpers.ts +12 -1
- package/src/index.ts +1 -1
- package/src/models.ts +399 -37
- package/src/schematic.ts +10 -0
- package/src/validation/property.validation.ts +37 -14
- package/types/constants.d.ts +4 -5
- package/types/helpers.d.ts +12 -1
- package/types/index.d.ts +1 -1
- package/types/models.d.ts +389 -12
- package/types/schematic.d.ts +10 -0
- package/types/validation/property.validation.d.ts +1 -1
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/array/compact.js +0 -12
- package/dist/node_modules/@oscarpalmer/atoms/dist/internal/string.js +0 -24
package/types/schematic.d.ts
CHANGED
|
@@ -9,14 +9,24 @@ export declare class Schematic<Model> {
|
|
|
9
9
|
constructor(properties: ValidatedProperty[]);
|
|
10
10
|
/**
|
|
11
11
|
* Does the value match the schema?
|
|
12
|
+
* @param value - Value to validate
|
|
13
|
+
* @returns `true` if the value matches the schema, otherwise `false`
|
|
12
14
|
*/
|
|
13
15
|
is(value: unknown): value is Model;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Create a schematic from a schema
|
|
19
|
+
* @template Model - Schema type
|
|
20
|
+
* @param schema - Schema to create the schematic from
|
|
21
|
+
* @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
|
|
22
|
+
* @returns A schematic for the given schema
|
|
17
23
|
*/
|
|
18
24
|
export declare function schematic<Model extends Schema>(schema: Model): Schematic<Infer<Model>>;
|
|
19
25
|
/**
|
|
20
26
|
* Create a schematic from a typed schema
|
|
27
|
+
* @template Model - Existing type
|
|
28
|
+
* @param schema - Typed schema to create the schematic from
|
|
29
|
+
* @throws Throws {@link SchematicError} if the schema can not be converted into a schematic
|
|
30
|
+
* @returns A schematic for the given typed schema
|
|
21
31
|
*/
|
|
22
32
|
export declare function schematic<Model extends PlainObject>(schema: TypedSchema<Model>): Schematic<Model>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PlainObject } from '@oscarpalmer/atoms/models';
|
|
2
2
|
import { type ValidatedProperty } from '../models';
|
|
3
|
-
export declare function getProperties(original: PlainObject, prefix?: string,
|
|
3
|
+
export declare function getProperties(original: PlainObject, prefix?: string, fromType?: boolean): ValidatedProperty[];
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function compact(array, strict) {
|
|
2
|
-
if (!Array.isArray(array)) return [];
|
|
3
|
-
if (strict === true) return array.filter(Boolean);
|
|
4
|
-
const { length } = array;
|
|
5
|
-
const compacted = [];
|
|
6
|
-
for (let index = 0; index < length; index += 1) {
|
|
7
|
-
const item = array[index];
|
|
8
|
-
if (item != null) compacted.push(item);
|
|
9
|
-
}
|
|
10
|
-
return compacted;
|
|
11
|
-
}
|
|
12
|
-
export { compact };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { compact } from "./array/compact.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get the string value from any value
|
|
4
|
-
* @param value Original value
|
|
5
|
-
* @returns String representation of the value
|
|
6
|
-
*/
|
|
7
|
-
function getString(value) {
|
|
8
|
-
if (typeof value === "string") return value;
|
|
9
|
-
if (value == null) return "";
|
|
10
|
-
if (typeof value === "function") return getString(value());
|
|
11
|
-
if (typeof value !== "object") return String(value);
|
|
12
|
-
const asString = String(value.valueOf?.() ?? value);
|
|
13
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Join an array of values into a string
|
|
17
|
-
* @param value Array of values
|
|
18
|
-
* @param delimiter Delimiter to use between values
|
|
19
|
-
* @returns Joined string
|
|
20
|
-
*/
|
|
21
|
-
function join(value, delimiter) {
|
|
22
|
-
return compact(value).map(getString).join(typeof delimiter === "string" ? delimiter : "");
|
|
23
|
-
}
|
|
24
|
-
export { join };
|