@defra/forms-model 3.0.291 → 3.0.292
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/package.json +1 -1
- package/src/utils/helpers.ts +0 -34
package/package.json
CHANGED
package/src/utils/helpers.ts
CHANGED
@@ -1,39 +1,5 @@
|
|
1
1
|
import slug from 'slug'
|
2
2
|
|
3
|
-
export const serialiseAndDeserialise = <T>(obj: T): T => {
|
4
|
-
if (typeof obj === 'object' && obj !== null) {
|
5
|
-
return JSON.parse(JSON.stringify(obj))
|
6
|
-
}
|
7
|
-
|
8
|
-
return obj
|
9
|
-
}
|
10
|
-
|
11
|
-
export const clone = <T>(obj: T & { clone?: () => T }): T => {
|
12
|
-
if (obj) {
|
13
|
-
if (typeof obj.clone === 'function') {
|
14
|
-
return obj.clone()
|
15
|
-
}
|
16
|
-
|
17
|
-
return serialiseAndDeserialise<T>(obj)
|
18
|
-
}
|
19
|
-
return obj
|
20
|
-
}
|
21
|
-
|
22
|
-
export function filter<T extends Record<string, unknown>>(
|
23
|
-
obj: T,
|
24
|
-
predicate: (value: any) => boolean
|
25
|
-
): Partial<T> {
|
26
|
-
const result = {}
|
27
|
-
|
28
|
-
for (const [key, value] of Object.entries(obj)) {
|
29
|
-
if (value && predicate(value)) {
|
30
|
-
result[key] = value
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
return result
|
35
|
-
}
|
36
|
-
|
37
3
|
/**
|
38
4
|
* Replace whitespace, en-dashes and em-dashes with spaces
|
39
5
|
* before running through the slug package
|