pacc 8.0.0 → 8.0.2

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 CHANGED
@@ -543,6 +543,7 @@ Split property path into tokens
543
543
  ### Parameters
544
544
 
545
545
  * `string` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
546
+ * `options` (optional, default `{}`)
546
547
 
547
548
  ## setAttribute
548
549
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pacc",
3
- "version": "8.0.0",
3
+ "version": "8.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -59,6 +59,7 @@ export { default_attribute_writable as string_attribute_writable };
59
59
 
60
60
  export const string_collection_attribute = {
61
61
  ...default_attribute,
62
+ separator: " ",
62
63
  collection: true
63
64
  };
64
65
 
package/src/types.mjs CHANGED
@@ -13,7 +13,26 @@ const emptyStringIsUndefined = value =>
13
13
  typeof value === "string" && value.length === 0 ? undefined : value;
14
14
 
15
15
  export const types = {
16
- string: { name: "string", primitive: true },
16
+ string: {
17
+ name: "string",
18
+ primitive: true,
19
+ toInternal: (value, attribute) => {
20
+ if (typeof value === "string") {
21
+ if (attribute.collection) {
22
+ return value.split(attribute.separator);
23
+ }
24
+ }
25
+ return value;
26
+ },
27
+ toExternal: (value, attribute) => {
28
+ if (value !== undefined) {
29
+ if (attribute.collection) {
30
+ return (Array.isArray(value) ? value : [...value]).join(attribute.separator);
31
+ }
32
+ }
33
+ return value;
34
+ }
35
+ },
17
36
  number: {
18
37
  name: "number",
19
38
  primitive: true,
@@ -55,7 +74,8 @@ export const types = {
55
74
  name: "duration",
56
75
  primitive: true,
57
76
  toInternal: value => parseDuration(value),
58
- toExternal: value => value === undefined ? undefined : formatDuration(value)
77
+ toExternal: value =>
78
+ value === undefined ? undefined : formatDuration(value)
59
79
  },
60
80
  duration_ms: {
61
81
  name: "duration_ms",
@@ -31,6 +31,7 @@ export const default_attribute: AttributeDefinition;
31
31
  */
32
32
  export const default_attribute_writable: AttributeDefinition;
33
33
  export namespace string_collection_attribute {
34
+ export let separator: string;
34
35
  export let collection: boolean;
35
36
  export let type: object;
36
37
  export let isKey: boolean;
package/types/types.d.mts CHANGED
@@ -6,6 +6,8 @@ export const types: {
6
6
  string: {
7
7
  name: string;
8
8
  primitive: boolean;
9
+ toInternal: (value: any, attribute: any) => any;
10
+ toExternal: (value: any, attribute: any) => any;
9
11
  };
10
12
  number: {
11
13
  name: string;