@worldware/msg 0.6.1 → 0.6.3

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
@@ -160,6 +160,9 @@ const jsonWithoutNotes = resource.toJSON(true);
160
160
 
161
161
  // Get data object
162
162
  const data = resource.getData();
163
+
164
+ // Message objects in the output only include `attributes` when they differ from
165
+ // the resource's attributes, keeping the serialized data compact
163
166
  ```
164
167
 
165
168
  ## API Reference
@@ -187,7 +190,7 @@ const data = resource.getData();
187
190
  - `translate(data: MsgResourceData): MsgResource` - Create a translated version
188
191
  - `getTranslation(lang: string): Promise<MsgResource>` - Load and apply translations
189
192
  - `getProject(): MsgProject` - Returns the project instance associated with the resource
190
- - `getData(stripNotes?: boolean): MsgResourceData` - Get resource data
193
+ - `getData(stripNotes?: boolean): MsgResourceData` - Get resource data. Message objects in the output omit `attributes` when they match the resource's attributes (to avoid redundancy)
191
194
  - `toJSON(stripNotes?: boolean): string` - Serialize to JSON
192
195
 
193
196
  **Properties:**
@@ -1,13 +1,13 @@
1
- import {
2
- DEFAULT_ATTRIBUTES
3
- } from "./chunk-OMRO6GAZ.mjs";
4
1
  import {
5
2
  MsgMessage
6
- } from "./chunk-GHRFKA7N.mjs";
3
+ } from "./chunk-WUDKNZV2.mjs";
4
+ import {
5
+ DEFAULT_ATTRIBUTES
6
+ } from "./chunk-QWBDIKQK.mjs";
7
7
 
8
8
  // src/classes/MsgResource/MsgResource.ts
9
9
  var MsgResource = class _MsgResource extends Map {
10
- _attributes = DEFAULT_ATTRIBUTES;
10
+ _attributes = {};
11
11
  _notes = [];
12
12
  _title;
13
13
  _project;
@@ -27,12 +27,17 @@ var MsgResource = class _MsgResource extends Map {
27
27
  constructor(title, attributes, project, notes) {
28
28
  super();
29
29
  this._title = title;
30
- this._attributes = { ...this._attributes, ...attributes };
30
+ this._attributes = { ...DEFAULT_ATTRIBUTES, ...attributes };
31
31
  this._project = project;
32
32
  if (notes) {
33
33
  notes.forEach((note) => this.addNote(note));
34
34
  }
35
35
  }
36
+ hasMatchingAttributes(message) {
37
+ const res = this.attributes;
38
+ const msg = message.attributes;
39
+ return res.lang === msg.lang && res.dir === msg.dir && res.dnt === msg.dnt;
40
+ }
36
41
  get attributes() {
37
42
  return this._attributes;
38
43
  }
@@ -117,7 +122,13 @@ var MsgResource = class _MsgResource extends Map {
117
122
  }
118
123
  getData(stripNotes = false) {
119
124
  const messages = [];
120
- this.forEach((msg) => messages.push(msg.getData(stripNotes)));
125
+ this.forEach((msg) => {
126
+ if (this.hasMatchingAttributes(msg)) {
127
+ messages.push({ key: msg.key, value: msg.value });
128
+ } else {
129
+ messages.push(msg.getData(stripNotes));
130
+ }
131
+ });
121
132
  return {
122
133
  title: this.title,
123
134
  attributes: this.attributes,
@@ -1,7 +1,7 @@
1
1
  // src/classes/MsgInterface/MsgInterface.ts
2
2
  var DEFAULT_ATTRIBUTES = {
3
- lang: "",
4
- dir: "",
3
+ lang: "und",
4
+ dir: "auto",
5
5
  dnt: false
6
6
  };
7
7
 
@@ -1,20 +1,19 @@
1
+ import {
2
+ DEFAULT_ATTRIBUTES
3
+ } from "./chunk-QWBDIKQK.mjs";
4
+
1
5
  // src/classes/MsgMessage/MsgMessage.ts
2
6
  import { MessageFormat } from "messageformat";
3
- var DEFAULT_ATTRIBUTES = {
4
- lang: "",
5
- dir: "",
6
- dnt: false
7
- };
8
7
  var MsgMessage = class _MsgMessage {
9
8
  _key;
10
9
  _value;
11
10
  _mf;
12
- _attributes = DEFAULT_ATTRIBUTES;
11
+ _attributes;
13
12
  _notes = [];
14
13
  constructor(key, value, attributes, notes) {
15
14
  this._key = key;
16
15
  this._value = value;
17
- this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
16
+ this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
18
17
  if (notes) {
19
18
  notes.forEach((note) => this.addNote(note));
20
19
  }
@@ -24,8 +24,8 @@ __export(MsgInterface_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(MsgInterface_exports);
26
26
  var DEFAULT_ATTRIBUTES = {
27
- lang: "",
28
- dir: "",
27
+ lang: "und",
28
+ dir: "auto",
29
29
  dnt: false
30
30
  };
31
31
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_ATTRIBUTES
3
- } from "../../chunk-OMRO6GAZ.mjs";
3
+ } from "../../chunk-QWBDIKQK.mjs";
4
4
  export {
5
5
  DEFAULT_ATTRIBUTES
6
6
  };
@@ -24,21 +24,25 @@ __export(MsgMessage_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(MsgMessage_exports);
26
26
  var import_messageformat = require("messageformat");
27
+
28
+ // src/classes/MsgInterface/MsgInterface.ts
27
29
  var DEFAULT_ATTRIBUTES = {
28
- lang: "",
29
- dir: "",
30
+ lang: "und",
31
+ dir: "auto",
30
32
  dnt: false
31
33
  };
34
+
35
+ // src/classes/MsgMessage/MsgMessage.ts
32
36
  var MsgMessage = class _MsgMessage {
33
37
  _key;
34
38
  _value;
35
39
  _mf;
36
- _attributes = DEFAULT_ATTRIBUTES;
40
+ _attributes;
37
41
  _notes = [];
38
42
  constructor(key, value, attributes, notes) {
39
43
  this._key = key;
40
44
  this._value = value;
41
- this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
45
+ this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
42
46
  if (notes) {
43
47
  notes.forEach((note) => this.addNote(note));
44
48
  }
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  MsgMessage
3
- } from "../../chunk-GHRFKA7N.mjs";
3
+ } from "../../chunk-WUDKNZV2.mjs";
4
+ import "../../chunk-QWBDIKQK.mjs";
4
5
  export {
5
6
  MsgMessage
6
7
  };
@@ -45,6 +45,7 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
45
45
  private _project;
46
46
  static create(data: MsgResourceData, project: MsgProject): MsgResource;
47
47
  private constructor();
48
+ private hasMatchingAttributes;
48
49
  get attributes(): MsgAttributes;
49
50
  set attributes(attributes: MsgAttributes);
50
51
  get notes(): MsgNote[];
@@ -45,6 +45,7 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
45
45
  private _project;
46
46
  static create(data: MsgResourceData, project: MsgProject): MsgResource;
47
47
  private constructor();
48
+ private hasMatchingAttributes;
48
49
  get attributes(): MsgAttributes;
49
50
  set attributes(attributes: MsgAttributes);
50
51
  get notes(): MsgNote[];
@@ -26,21 +26,25 @@ module.exports = __toCommonJS(MsgResource_exports);
26
26
 
27
27
  // src/classes/MsgMessage/MsgMessage.ts
28
28
  var import_messageformat = require("messageformat");
29
+
30
+ // src/classes/MsgInterface/MsgInterface.ts
29
31
  var DEFAULT_ATTRIBUTES = {
30
- lang: "",
31
- dir: "",
32
+ lang: "und",
33
+ dir: "auto",
32
34
  dnt: false
33
35
  };
36
+
37
+ // src/classes/MsgMessage/MsgMessage.ts
34
38
  var MsgMessage = class _MsgMessage {
35
39
  _key;
36
40
  _value;
37
41
  _mf;
38
- _attributes = DEFAULT_ATTRIBUTES;
42
+ _attributes;
39
43
  _notes = [];
40
44
  constructor(key, value, attributes, notes) {
41
45
  this._key = key;
42
46
  this._value = value;
43
- this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
47
+ this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
44
48
  if (notes) {
45
49
  notes.forEach((note) => this.addNote(note));
46
50
  }
@@ -93,16 +97,9 @@ var MsgMessage = class _MsgMessage {
93
97
  }
94
98
  };
95
99
 
96
- // src/classes/MsgInterface/MsgInterface.ts
97
- var DEFAULT_ATTRIBUTES2 = {
98
- lang: "",
99
- dir: "",
100
- dnt: false
101
- };
102
-
103
100
  // src/classes/MsgResource/MsgResource.ts
104
101
  var MsgResource = class _MsgResource extends Map {
105
- _attributes = DEFAULT_ATTRIBUTES2;
102
+ _attributes = {};
106
103
  _notes = [];
107
104
  _title;
108
105
  _project;
@@ -122,12 +119,17 @@ var MsgResource = class _MsgResource extends Map {
122
119
  constructor(title, attributes, project, notes) {
123
120
  super();
124
121
  this._title = title;
125
- this._attributes = { ...this._attributes, ...attributes };
122
+ this._attributes = { ...DEFAULT_ATTRIBUTES, ...attributes };
126
123
  this._project = project;
127
124
  if (notes) {
128
125
  notes.forEach((note) => this.addNote(note));
129
126
  }
130
127
  }
128
+ hasMatchingAttributes(message) {
129
+ const res = this.attributes;
130
+ const msg = message.attributes;
131
+ return res.lang === msg.lang && res.dir === msg.dir && res.dnt === msg.dnt;
132
+ }
131
133
  get attributes() {
132
134
  return this._attributes;
133
135
  }
@@ -212,7 +214,13 @@ var MsgResource = class _MsgResource extends Map {
212
214
  }
213
215
  getData(stripNotes = false) {
214
216
  const messages = [];
215
- this.forEach((msg) => messages.push(msg.getData(stripNotes)));
217
+ this.forEach((msg) => {
218
+ if (this.hasMatchingAttributes(msg)) {
219
+ messages.push({ key: msg.key, value: msg.value });
220
+ } else {
221
+ messages.push(msg.getData(stripNotes));
222
+ }
223
+ });
216
224
  return {
217
225
  title: this.title,
218
226
  attributes: this.attributes,
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  MsgResource
3
- } from "../../chunk-4SWDABOO.mjs";
4
- import "../../chunk-OMRO6GAZ.mjs";
5
- import "../../chunk-GHRFKA7N.mjs";
3
+ } from "../../chunk-7LI2M4JY.mjs";
4
+ import "../../chunk-WUDKNZV2.mjs";
5
+ import "../../chunk-QWBDIKQK.mjs";
6
6
  export {
7
7
  MsgResource
8
8
  };
@@ -28,21 +28,25 @@ module.exports = __toCommonJS(classes_exports);
28
28
 
29
29
  // src/classes/MsgMessage/MsgMessage.ts
30
30
  var import_messageformat = require("messageformat");
31
+
32
+ // src/classes/MsgInterface/MsgInterface.ts
31
33
  var DEFAULT_ATTRIBUTES = {
32
- lang: "",
33
- dir: "",
34
+ lang: "und",
35
+ dir: "auto",
34
36
  dnt: false
35
37
  };
38
+
39
+ // src/classes/MsgMessage/MsgMessage.ts
36
40
  var MsgMessage = class _MsgMessage {
37
41
  _key;
38
42
  _value;
39
43
  _mf;
40
- _attributes = DEFAULT_ATTRIBUTES;
44
+ _attributes;
41
45
  _notes = [];
42
46
  constructor(key, value, attributes, notes) {
43
47
  this._key = key;
44
48
  this._value = value;
45
- this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
49
+ this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
46
50
  if (notes) {
47
51
  notes.forEach((note) => this.addNote(note));
48
52
  }
@@ -95,16 +99,9 @@ var MsgMessage = class _MsgMessage {
95
99
  }
96
100
  };
97
101
 
98
- // src/classes/MsgInterface/MsgInterface.ts
99
- var DEFAULT_ATTRIBUTES2 = {
100
- lang: "",
101
- dir: "",
102
- dnt: false
103
- };
104
-
105
102
  // src/classes/MsgResource/MsgResource.ts
106
103
  var MsgResource = class _MsgResource extends Map {
107
- _attributes = DEFAULT_ATTRIBUTES2;
104
+ _attributes = {};
108
105
  _notes = [];
109
106
  _title;
110
107
  _project;
@@ -124,12 +121,17 @@ var MsgResource = class _MsgResource extends Map {
124
121
  constructor(title, attributes, project, notes) {
125
122
  super();
126
123
  this._title = title;
127
- this._attributes = { ...this._attributes, ...attributes };
124
+ this._attributes = { ...DEFAULT_ATTRIBUTES, ...attributes };
128
125
  this._project = project;
129
126
  if (notes) {
130
127
  notes.forEach((note) => this.addNote(note));
131
128
  }
132
129
  }
130
+ hasMatchingAttributes(message) {
131
+ const res = this.attributes;
132
+ const msg = message.attributes;
133
+ return res.lang === msg.lang && res.dir === msg.dir && res.dnt === msg.dnt;
134
+ }
133
135
  get attributes() {
134
136
  return this._attributes;
135
137
  }
@@ -214,7 +216,13 @@ var MsgResource = class _MsgResource extends Map {
214
216
  }
215
217
  getData(stripNotes = false) {
216
218
  const messages = [];
217
- this.forEach((msg) => messages.push(msg.getData(stripNotes)));
219
+ this.forEach((msg) => {
220
+ if (this.hasMatchingAttributes(msg)) {
221
+ messages.push({ key: msg.key, value: msg.value });
222
+ } else {
223
+ messages.push(msg.getData(stripNotes));
224
+ }
225
+ });
218
226
  return {
219
227
  title: this.title,
220
228
  attributes: this.attributes,
@@ -4,11 +4,11 @@ import {
4
4
  } from "../chunk-XS43NAP2.mjs";
5
5
  import {
6
6
  MsgResource
7
- } from "../chunk-4SWDABOO.mjs";
8
- import "../chunk-OMRO6GAZ.mjs";
7
+ } from "../chunk-7LI2M4JY.mjs";
9
8
  import {
10
9
  MsgMessage
11
- } from "../chunk-GHRFKA7N.mjs";
10
+ } from "../chunk-WUDKNZV2.mjs";
11
+ import "../chunk-QWBDIKQK.mjs";
12
12
  export {
13
13
  MsgMessage,
14
14
  MsgProject,
package/dist/index.cjs CHANGED
@@ -28,21 +28,25 @@ module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/classes/MsgMessage/MsgMessage.ts
30
30
  var import_messageformat = require("messageformat");
31
+
32
+ // src/classes/MsgInterface/MsgInterface.ts
31
33
  var DEFAULT_ATTRIBUTES = {
32
- lang: "",
33
- dir: "",
34
+ lang: "und",
35
+ dir: "auto",
34
36
  dnt: false
35
37
  };
38
+
39
+ // src/classes/MsgMessage/MsgMessage.ts
36
40
  var MsgMessage = class _MsgMessage {
37
41
  _key;
38
42
  _value;
39
43
  _mf;
40
- _attributes = DEFAULT_ATTRIBUTES;
44
+ _attributes;
41
45
  _notes = [];
42
46
  constructor(key, value, attributes, notes) {
43
47
  this._key = key;
44
48
  this._value = value;
45
- this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
49
+ this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
46
50
  if (notes) {
47
51
  notes.forEach((note) => this.addNote(note));
48
52
  }
@@ -95,16 +99,9 @@ var MsgMessage = class _MsgMessage {
95
99
  }
96
100
  };
97
101
 
98
- // src/classes/MsgInterface/MsgInterface.ts
99
- var DEFAULT_ATTRIBUTES2 = {
100
- lang: "",
101
- dir: "",
102
- dnt: false
103
- };
104
-
105
102
  // src/classes/MsgResource/MsgResource.ts
106
103
  var MsgResource = class _MsgResource extends Map {
107
- _attributes = DEFAULT_ATTRIBUTES2;
104
+ _attributes = {};
108
105
  _notes = [];
109
106
  _title;
110
107
  _project;
@@ -124,12 +121,17 @@ var MsgResource = class _MsgResource extends Map {
124
121
  constructor(title, attributes, project, notes) {
125
122
  super();
126
123
  this._title = title;
127
- this._attributes = { ...this._attributes, ...attributes };
124
+ this._attributes = { ...DEFAULT_ATTRIBUTES, ...attributes };
128
125
  this._project = project;
129
126
  if (notes) {
130
127
  notes.forEach((note) => this.addNote(note));
131
128
  }
132
129
  }
130
+ hasMatchingAttributes(message) {
131
+ const res = this.attributes;
132
+ const msg = message.attributes;
133
+ return res.lang === msg.lang && res.dir === msg.dir && res.dnt === msg.dnt;
134
+ }
133
135
  get attributes() {
134
136
  return this._attributes;
135
137
  }
@@ -214,7 +216,13 @@ var MsgResource = class _MsgResource extends Map {
214
216
  }
215
217
  getData(stripNotes = false) {
216
218
  const messages = [];
217
- this.forEach((msg) => messages.push(msg.getData(stripNotes)));
219
+ this.forEach((msg) => {
220
+ if (this.hasMatchingAttributes(msg)) {
221
+ messages.push({ key: msg.key, value: msg.value });
222
+ } else {
223
+ messages.push(msg.getData(stripNotes));
224
+ }
225
+ });
218
226
  return {
219
227
  title: this.title,
220
228
  attributes: this.attributes,
package/dist/index.mjs CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  } from "./chunk-XS43NAP2.mjs";
5
5
  import {
6
6
  MsgResource
7
- } from "./chunk-4SWDABOO.mjs";
8
- import "./chunk-OMRO6GAZ.mjs";
7
+ } from "./chunk-7LI2M4JY.mjs";
9
8
  import {
10
9
  MsgMessage
11
- } from "./chunk-GHRFKA7N.mjs";
10
+ } from "./chunk-WUDKNZV2.mjs";
11
+ import "./chunk-QWBDIKQK.mjs";
12
12
  export {
13
13
  MsgMessage,
14
14
  MsgProject,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Message localization tooling",
5
5
  "license": "MIT",
6
6
  "author": "Joel Sahleen",