@myrmidon/cadmus-profile-core 13.0.1 → 20.0.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.
@@ -1,370 +1,289 @@
1
- import * as i0 from '@angular/core';
2
- import { Injectable } from '@angular/core';
3
-
1
+ import * as i0 from "@angular/core";
2
+ import { Injectable } from "@angular/core";
4
3
  const DEFAULT_OPTIONS = {
5
- fieldSeparator: ',',
6
- lineSeparator: '\n',
7
- quote: '"',
8
- trimming: true,
4
+ fieldSeparator: ",",
5
+ lineSeparator: "\n",
6
+ quote: "\"",
7
+ trimming: true
9
8
  };
10
9
  const CSV_INITAL_STATE = {
11
- field: 0,
12
- fieldOffset: 0,
13
- line: 0,
14
- lineOffset: 0,
15
- quoted: false,
16
- appendCell: false,
17
- appendField: false,
18
- appendRow: false,
10
+ field: 0,
11
+ fieldOffset: 0,
12
+ line: 0,
13
+ lineOffset: 0,
14
+ quoted: false,
15
+ appendCell: false,
16
+ appendField: false,
17
+ appendRow: false
19
18
  };
20
- class ParseError extends Error {
21
- constructor(line, column) {
22
- super(`Invalid CSV at ${line}:${column}`);
23
- }
24
- }
25
- /**
26
- * CSV text reader.
27
- * Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.
28
- */
29
- class CsvReader {
30
- _text;
31
- _lastRow = [];
32
- _row = [];
33
- _cell = '';
34
- _options = DEFAULT_OPTIONS;
35
- _state = { ...CSV_INITAL_STATE };
36
- _index = 0;
37
- _current = '';
38
- _previous = '';
39
- constructor(text, options) {
40
- this._text = text;
41
- this._options = Object.assign({}, DEFAULT_OPTIONS, options || {});
42
- this.reset();
43
- }
44
- /**
45
- * Read the next row from the CSV text.
46
- *
47
- * @param text - CSV text
48
- * @returns array of fields, each being an array of strings.
49
- * @throws Error on parse error
50
- */
51
- read() {
52
- while (this._index < this._text.length) {
53
- this._state.appendCell = true;
54
- this._previous = this._current;
55
- this._current = this._text[this._index];
56
- if (this.handleNext()) {
57
- this._index++;
58
- return this._lastRow;
59
- }
60
- this._index++;
61
- }
62
- if (this._row.length > 0) {
63
- this.addField(this.fieldValue(this._cell), this._row, this._state);
64
- this.nextRow(this._row, this._state);
65
- this._row.length = 0;
66
- return this._lastRow;
67
- }
68
- return null;
69
- }
70
- handleNext() {
71
- this.handleQuote() ||
72
- this.handleFieldSeparator() ||
73
- this.handleLineSeparator();
74
- return this.processState();
75
- }
76
- handleQuote() {
77
- if (this._current === this._options.quote) {
78
- // a quote is "escaped" (a literal quote character inside a quoted
79
- // field) only when preceded by a backslash. _previous starts as ''
80
- // (never '\\'), so this already correctly treats a quote at index 0
81
- // as unescaped without needing an extra `this._index &&` guard - that
82
- // guard used to force EVERY quote at index 0 down the "escaped"
83
- // branch instead, since 0 is falsy, which broke parsing of any row
84
- // whose first field is quoted (e.g. `"a",b`) with a spurious
85
- // ParseError.
86
- if (this._previous !== '\\') {
87
- this.handleQuoteNotEscaped();
88
- }
89
- else {
90
- this.handleQuoteEscaped();
91
- }
92
- return true;
93
- }
94
- return false;
95
- }
96
- handleQuoteEscaped() {
97
- this._cell = this._cell.slice(0, Math.max(0, this._cell.length - 1));
98
- }
99
- handleQuoteNotEscaped() {
100
- if (this._cell.length === 0 || this._state.quoted) {
101
- this._state.quoted = !this._state.quoted;
102
- }
103
- else {
104
- throw new ParseError(this._state.line, this._state.lineOffset);
105
- }
106
- this._state.appendCell = false;
107
- }
108
- handleFieldSeparator() {
109
- if (this._current === this._options.fieldSeparator) {
110
- if (!this._state.quoted) {
111
- this._state.appendCell = false;
112
- this._state.appendField = true;
113
- }
114
- return true;
115
- }
116
- return false;
117
- }
118
- handleLineSeparator() {
119
- if (this._current === this._options.lineSeparator) {
120
- if (!this._state.quoted) {
121
- this._state.appendCell = false;
122
- this._state.appendField = true;
123
- this._state.appendRow = true;
124
- }
125
- return true;
126
- }
127
- return false;
128
- }
129
- processState() {
130
- let end = false;
131
- if (this._state.appendCell) {
132
- this._cell += this._current;
133
- }
134
- if (this._state.appendField) {
135
- this.addField(this.fieldValue(this._cell), this._row, this._state);
136
- this._cell = '';
137
- }
138
- if (this._state.appendRow) {
139
- this.nextRow(this._row, this._state);
140
- this._row = [];
141
- end = true;
142
- }
143
- this._state.lineOffset++;
144
- this._state.fieldOffset++;
145
- return end;
146
- }
147
- fieldValue(cell) {
148
- return cell;
149
- }
150
- addField(field, row, state) {
151
- row.push(this._options.trimming ? field.trim() : field);
152
- state.field++;
153
- state.fieldOffset = -1;
154
- state.appendField = false;
155
- }
156
- nextRow(row, state) {
157
- this._lastRow = [...row];
158
- state.field = 0;
159
- state.line++;
160
- state.lineOffset = -1;
161
- state.appendRow = false;
162
- }
163
- reset() {
164
- this._lastRow = [];
165
- this._row = [];
166
- this._cell = '';
167
- this._state = { ...CSV_INITAL_STATE };
168
- this._index = 0;
169
- this._current = '';
170
- this._previous = '';
171
- }
172
- }
173
-
174
- /**
175
- * CSV thesaurus reader. This reads any number of thesauri from a CSV text.
176
- * By convention, the CSV has column 1=ID and column 2=value for each
177
- * thesaurus entry. Each thesaurus is started by a row having in the ID
178
- * the thesaurus ID and an empty value.
179
- * If a thesaurus ID is just an alias, the value starts with an equal sign
180
- * (e.g. "biblio-languages,=languages") and has no other entries.
181
- */
182
- class CsvThesaurusReader {
183
- _csvReader;
184
- _id;
185
- _targetId;
186
- _entries;
187
- _eof;
188
- constructor(text, options) {
189
- this._csvReader = new CsvReader(text, options);
190
- this._entries = [];
191
- }
192
- parseLanguage(id) {
193
- const i = id.lastIndexOf('@');
194
- return i > -1 ? id.substring(i + 1) : 'en';
195
- }
196
- getThesaurus() {
197
- if (!this._id) {
198
- return null;
199
- }
200
- return {
201
- id: this._id,
202
- language: this.parseLanguage(this._id),
203
- targetId: this._targetId,
204
- entries: this._targetId ? undefined : [...this._entries],
205
- };
206
- }
207
- reset() {
208
- this._id = undefined;
209
- this._targetId = undefined;
210
- this._entries.length = 0;
211
- }
212
- /**
213
- * Read the next thesaurus if any.
214
- *
215
- * @returns Thesaurus or null if end of CSV text reached.
216
- */
217
- read() {
218
- if (this._eof) {
219
- return null;
220
- }
221
- while (true) {
222
- // read the next row
223
- const row = this._csvReader.read();
224
- // if no more rows, ret the last thesaurus if any
225
- if (!row) {
226
- this._eof = true;
227
- const last = this.getThesaurus();
228
- this.reset();
229
- return last;
230
- }
231
- // an empty value starts a new thesaurus
232
- if (!row[1]) {
233
- const prev = this.getThesaurus();
234
- this.reset();
235
- this._id = row[0];
236
- // return the previous thesaurus if any
237
- if (prev) {
238
- return prev;
239
- }
240
- }
241
- else if (row[1].startsWith('=') && row[1].length > 1) {
242
- // a value starting with = is the alias target
243
- const prev = this.getThesaurus();
244
- this.reset();
245
- this._id = row[0];
246
- this._targetId = row[1].substring(1);
247
- // return the previous thesaurus if any
248
- if (prev) {
249
- return prev;
250
- }
251
- }
252
- else {
253
- this._entries.push({
254
- id: row[0],
255
- value: row[1],
256
- });
257
- }
258
- }
259
- }
260
- }
261
-
262
- /**
263
- * Utility functions for Cadmus profile data.
264
- */
265
- class ProfileUtilService {
266
- constructor() { }
267
- /**
268
- * Group an array of objects by 1 or more of its string properties.
269
- *
270
- * @param arr The array of objects to group.
271
- * @param keys The keys to be used in grouping objects. It is assumed
272
- * that such keys are all string properties.
273
- * @returns An object where each property is a key with value equal
274
- * to an array of items.
275
- */
276
- groupIntoObject(arr, keys) {
277
- // https://gist.github.com/robmathers/1830ce09695f759bf2c4df15c29dd22d
278
- return arr.reduce((storage, item) => {
279
- const compositeKey = keys.map((key) => `${item[key]}`).join(':');
280
- if (storage[compositeKey]) {
281
- storage[compositeKey].push(item);
282
- }
283
- else {
284
- storage[compositeKey] = [item];
285
- }
286
- return storage;
287
- }, {});
288
- }
289
- /**
290
- * Group an array of objects by 1 or more of its string properties,
291
- * storing the result into an array of KeyedGroup<T>.
292
- *
293
- * @param arr The array of objects to group.
294
- * @param keys The keys to be used in grouping objects. It is assumed
295
- * that such keys are all string properties.
296
- * @returns An array of KeyedGroup<T>.
297
- */
298
- groupIntoKeyedGroups(arr, keys) {
299
- let storage = new Map();
300
- storage = arr.reduce((storage, item) => {
301
- const compositeKey = keys.map((key) => `${item[key]}`).join(':');
302
- if (storage.has(compositeKey)) {
303
- storage.set(compositeKey, [...(storage.get(compositeKey) || []), item]);
304
- }
305
- else {
306
- storage.set(compositeKey, [item]);
307
- }
308
- return storage;
309
- }, storage);
310
- const groups = [];
311
- const sortedKeys = [...storage.keys()].sort();
312
- for (let key of sortedKeys) {
313
- groups.push({
314
- key: key,
315
- items: storage.get(key),
316
- });
317
- }
318
- return groups;
319
- }
320
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: ProfileUtilService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
321
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: ProfileUtilService, providedIn: 'root' });
322
- }
323
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: ProfileUtilService, decorators: [{
324
- type: Injectable,
325
- args: [{
326
- providedIn: 'root',
327
- }]
328
- }], ctorParameters: () => [] });
329
-
330
- /**
331
- * Service to let user download a text file generated into a string.
332
- */
333
- class TextToFileService {
334
- constructor() { }
335
- /**
336
- * Save the specified text into a file.
337
- *
338
- * @param text The text content to be saved.
339
- * @param name The file name.
340
- * @param contentType The content type.
341
- */
342
- saveToFile(text, name, contentType = 'text/plain') {
343
- // https://robkendal.co.uk/blog/2020-04-17-saving-text-to-client-side-file-using-vanilla-js
344
- const a = document.createElement('a');
345
- const file = new Blob([text], { type: contentType });
346
- a.href = URL.createObjectURL(file);
347
- a.download = name;
348
- a.click();
349
- URL.revokeObjectURL(a.href);
350
- }
351
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextToFileService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
352
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextToFileService, providedIn: 'root' });
353
- }
354
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.1", ngImport: i0, type: TextToFileService, decorators: [{
355
- type: Injectable,
356
- args: [{
357
- providedIn: 'root',
358
- }]
359
- }], ctorParameters: () => [] });
360
-
361
- /*
362
- * Public API Surface of cadmus-profile-core
363
- */
364
-
365
- /**
366
- * Generated bundle index. Do not edit.
367
- */
368
-
19
+ var ParseError = class extends Error {
20
+ constructor(line, column) {
21
+ super(`Invalid CSV at ${line}:${column}`);
22
+ }
23
+ };
24
+ var CsvReader = class {
25
+ _text;
26
+ _lastRow = [];
27
+ _row = [];
28
+ _cell = "";
29
+ _options = DEFAULT_OPTIONS;
30
+ _state = { ...CSV_INITAL_STATE };
31
+ _index = 0;
32
+ _current = "";
33
+ _previous = "";
34
+ constructor(text, options) {
35
+ this._text = text;
36
+ this._options = Object.assign({}, DEFAULT_OPTIONS, options || {});
37
+ this.reset();
38
+ }
39
+ read() {
40
+ while (this._index < this._text.length) {
41
+ this._state.appendCell = true;
42
+ this._previous = this._current;
43
+ this._current = this._text[this._index];
44
+ if (this.handleNext()) {
45
+ this._index++;
46
+ return this._lastRow;
47
+ }
48
+ this._index++;
49
+ }
50
+ if (this._row.length > 0) {
51
+ this.addField(this.fieldValue(this._cell), this._row, this._state);
52
+ this.nextRow(this._row, this._state);
53
+ this._row.length = 0;
54
+ return this._lastRow;
55
+ }
56
+ return null;
57
+ }
58
+ handleNext() {
59
+ this.handleQuote() || this.handleFieldSeparator() || this.handleLineSeparator();
60
+ return this.processState();
61
+ }
62
+ handleQuote() {
63
+ if (this._current === this._options.quote) {
64
+ if (this._previous !== "\\") this.handleQuoteNotEscaped();
65
+ else this.handleQuoteEscaped();
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+ handleQuoteEscaped() {
71
+ this._cell = this._cell.slice(0, Math.max(0, this._cell.length - 1));
72
+ }
73
+ handleQuoteNotEscaped() {
74
+ if (this._cell.length === 0 || this._state.quoted) this._state.quoted = !this._state.quoted;
75
+ else throw new ParseError(this._state.line, this._state.lineOffset);
76
+ this._state.appendCell = false;
77
+ }
78
+ handleFieldSeparator() {
79
+ if (this._current === this._options.fieldSeparator) {
80
+ if (!this._state.quoted) {
81
+ this._state.appendCell = false;
82
+ this._state.appendField = true;
83
+ }
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ handleLineSeparator() {
89
+ if (this._current === this._options.lineSeparator) {
90
+ if (!this._state.quoted) {
91
+ this._state.appendCell = false;
92
+ this._state.appendField = true;
93
+ this._state.appendRow = true;
94
+ }
95
+ return true;
96
+ }
97
+ return false;
98
+ }
99
+ processState() {
100
+ let end = false;
101
+ if (this._state.appendCell) this._cell += this._current;
102
+ if (this._state.appendField) {
103
+ this.addField(this.fieldValue(this._cell), this._row, this._state);
104
+ this._cell = "";
105
+ }
106
+ if (this._state.appendRow) {
107
+ this.nextRow(this._row, this._state);
108
+ this._row = [];
109
+ end = true;
110
+ }
111
+ this._state.lineOffset++;
112
+ this._state.fieldOffset++;
113
+ return end;
114
+ }
115
+ fieldValue(cell) {
116
+ return cell;
117
+ }
118
+ addField(field, row, state) {
119
+ row.push(this._options.trimming ? field.trim() : field);
120
+ state.field++;
121
+ state.fieldOffset = -1;
122
+ state.appendField = false;
123
+ }
124
+ nextRow(row, state) {
125
+ this._lastRow = [...row];
126
+ state.field = 0;
127
+ state.line++;
128
+ state.lineOffset = -1;
129
+ state.appendRow = false;
130
+ }
131
+ reset() {
132
+ this._lastRow = [];
133
+ this._row = [];
134
+ this._cell = "";
135
+ this._state = { ...CSV_INITAL_STATE };
136
+ this._index = 0;
137
+ this._current = "";
138
+ this._previous = "";
139
+ }
140
+ };
141
+ var CsvThesaurusReader = class {
142
+ _csvReader;
143
+ _id;
144
+ _targetId;
145
+ _entries;
146
+ _eof;
147
+ constructor(text, options) {
148
+ this._csvReader = new CsvReader(text, options);
149
+ this._entries = [];
150
+ }
151
+ parseLanguage(id) {
152
+ const i = id.lastIndexOf("@");
153
+ return i > -1 ? id.substring(i + 1) : "en";
154
+ }
155
+ getThesaurus() {
156
+ if (!this._id) return null;
157
+ return {
158
+ id: this._id,
159
+ language: this.parseLanguage(this._id),
160
+ targetId: this._targetId,
161
+ entries: this._targetId ? void 0 : [...this._entries]
162
+ };
163
+ }
164
+ reset() {
165
+ this._id = void 0;
166
+ this._targetId = void 0;
167
+ this._entries.length = 0;
168
+ }
169
+ read() {
170
+ if (this._eof) return null;
171
+ while (true) {
172
+ const row = this._csvReader.read();
173
+ if (!row) {
174
+ this._eof = true;
175
+ const last = this.getThesaurus();
176
+ this.reset();
177
+ return last;
178
+ }
179
+ if (!row[1]) {
180
+ const prev = this.getThesaurus();
181
+ this.reset();
182
+ this._id = row[0];
183
+ if (prev) return prev;
184
+ } else if (row[1].startsWith("=") && row[1].length > 1) {
185
+ const prev = this.getThesaurus();
186
+ this.reset();
187
+ this._id = row[0];
188
+ this._targetId = row[1].substring(1);
189
+ if (prev) return prev;
190
+ } else this._entries.push({
191
+ id: row[0],
192
+ value: row[1]
193
+ });
194
+ }
195
+ }
196
+ };
197
+ var ProfileUtilService = class ProfileUtilService {
198
+ constructor() {}
199
+ groupIntoObject(arr, keys) {
200
+ return arr.reduce((storage, item) => {
201
+ const compositeKey = keys.map((key) => `${item[key]}`).join(":");
202
+ if (storage[compositeKey]) storage[compositeKey].push(item);
203
+ else storage[compositeKey] = [item];
204
+ return storage;
205
+ }, {});
206
+ }
207
+ groupIntoKeyedGroups(arr, keys) {
208
+ let storage = /* @__PURE__ */ new Map();
209
+ storage = arr.reduce((storage, item) => {
210
+ const compositeKey = keys.map((key) => `${item[key]}`).join(":");
211
+ if (storage.has(compositeKey)) storage.set(compositeKey, [...storage.get(compositeKey) || [], item]);
212
+ else storage.set(compositeKey, [item]);
213
+ return storage;
214
+ }, storage);
215
+ const groups = [];
216
+ const sortedKeys = [...storage.keys()].sort();
217
+ for (let key of sortedKeys) groups.push({
218
+ key,
219
+ items: storage.get(key)
220
+ });
221
+ return groups;
222
+ }
223
+ static ɵfac = i0.ɵɵngDeclareFactory({
224
+ minVersion: "12.0.0",
225
+ version: "22.2.0",
226
+ ngImport: i0,
227
+ type: ProfileUtilService,
228
+ deps: [],
229
+ target: i0.ɵɵFactoryTarget.Injectable
230
+ });
231
+ static ɵprov = i0.ɵɵngDeclareInjectable({
232
+ minVersion: "12.0.0",
233
+ version: "22.2.0",
234
+ ngImport: i0,
235
+ type: ProfileUtilService,
236
+ providedIn: "root"
237
+ });
238
+ };
239
+ i0.ɵɵngDeclareClassMetadata({
240
+ minVersion: "12.0.0",
241
+ version: "22.2.0",
242
+ ngImport: i0,
243
+ type: ProfileUtilService,
244
+ decorators: [{
245
+ type: Injectable,
246
+ args: [{ providedIn: "root" }]
247
+ }],
248
+ ctorParameters: () => []
249
+ });
250
+ var TextToFileService = class TextToFileService {
251
+ constructor() {}
252
+ saveToFile(text, name, contentType = "text/plain") {
253
+ const a = document.createElement("a");
254
+ const file = new Blob([text], { type: contentType });
255
+ a.href = URL.createObjectURL(file);
256
+ a.download = name;
257
+ a.click();
258
+ URL.revokeObjectURL(a.href);
259
+ }
260
+ static ɵfac = i0.ɵɵngDeclareFactory({
261
+ minVersion: "12.0.0",
262
+ version: "22.2.0",
263
+ ngImport: i0,
264
+ type: TextToFileService,
265
+ deps: [],
266
+ target: i0.ɵɵFactoryTarget.Injectable
267
+ });
268
+ static ɵprov = i0.ɵɵngDeclareInjectable({
269
+ minVersion: "12.0.0",
270
+ version: "22.2.0",
271
+ ngImport: i0,
272
+ type: TextToFileService,
273
+ providedIn: "root"
274
+ });
275
+ };
276
+ i0.ɵɵngDeclareClassMetadata({
277
+ minVersion: "12.0.0",
278
+ version: "22.2.0",
279
+ ngImport: i0,
280
+ type: TextToFileService,
281
+ decorators: [{
282
+ type: Injectable,
283
+ args: [{ providedIn: "root" }]
284
+ }],
285
+ ctorParameters: () => []
286
+ });
369
287
  export { CsvReader, CsvThesaurusReader, ProfileUtilService, TextToFileService };
370
- //# sourceMappingURL=myrmidon-cadmus-profile-core.mjs.map
288
+
289
+ //# sourceMappingURL=myrmidon-cadmus-profile-core.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"myrmidon-cadmus-profile-core.mjs","sources":["../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/csv-reader.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/csv-thesaurus-reader.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/profile-util.service.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/text-to-file.service.ts","../../../../projects/myrmidon/cadmus-profile-core/src/public-api.ts","../../../../projects/myrmidon/cadmus-profile-core/src/myrmidon-cadmus-profile-core.ts"],"sourcesContent":["/**\r\n * Options for CsvReader.\r\n */\r\nexport interface CsvReaderOptions {\r\n fieldSeparator?: string;\r\n lineSeparator?: string;\r\n quote?: string;\r\n trimming?: boolean;\r\n}\r\n\r\nconst DEFAULT_OPTIONS = {\r\n fieldSeparator: ',',\r\n lineSeparator: '\\n',\r\n quote: '\"',\r\n trimming: true,\r\n};\r\n\r\ninterface State {\r\n appendCell: boolean;\r\n appendField: boolean;\r\n appendRow: boolean;\r\n field: number;\r\n fieldOffset: number;\r\n line: number;\r\n lineOffset: number;\r\n quoted: boolean;\r\n}\r\n\r\nconst CSV_INITAL_STATE = {\r\n field: 0,\r\n fieldOffset: 0,\r\n line: 0,\r\n lineOffset: 0,\r\n quoted: false,\r\n appendCell: false,\r\n appendField: false,\r\n appendRow: false,\r\n} as State;\r\n\r\nclass ParseError extends Error {\r\n public constructor(line: number, column: number) {\r\n super(`Invalid CSV at ${line}:${column}`);\r\n }\r\n}\r\n\r\n/**\r\n * CSV text reader.\r\n * Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.\r\n */\r\nexport class CsvReader {\r\n private readonly _text: string;\r\n private _lastRow = [] as string[];\r\n private _row = [] as string[];\r\n private _cell = '';\r\n private _options = DEFAULT_OPTIONS;\r\n private _state = { ...CSV_INITAL_STATE };\r\n private _index = 0;\r\n private _current = '';\r\n private _previous = '';\r\n\r\n constructor(text: string, options?: CsvReaderOptions) {\r\n this._text = text;\r\n this._options = Object.assign({}, DEFAULT_OPTIONS, options || {});\r\n this.reset();\r\n }\r\n\r\n /**\r\n * Read the next row from the CSV text.\r\n *\r\n * @param text - CSV text\r\n * @returns array of fields, each being an array of strings.\r\n * @throws Error on parse error\r\n */\r\n public read(): readonly string[] | null {\r\n while (this._index < this._text.length) {\r\n this._state.appendCell = true;\r\n this._previous = this._current;\r\n this._current = this._text[this._index];\r\n if (this.handleNext()) {\r\n this._index++;\r\n return this._lastRow;\r\n }\r\n this._index++;\r\n }\r\n\r\n if (this._row.length > 0) {\r\n this.addField(this.fieldValue(this._cell), this._row, this._state);\r\n this.nextRow(this._row, this._state);\r\n this._row.length = 0;\r\n return this._lastRow;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private handleNext(): boolean {\r\n this.handleQuote() ||\r\n this.handleFieldSeparator() ||\r\n this.handleLineSeparator();\r\n return this.processState();\r\n }\r\n\r\n private handleQuote() {\r\n if (this._current === this._options.quote) {\r\n // a quote is \"escaped\" (a literal quote character inside a quoted\r\n // field) only when preceded by a backslash. _previous starts as ''\r\n // (never '\\\\'), so this already correctly treats a quote at index 0\r\n // as unescaped without needing an extra `this._index &&` guard - that\r\n // guard used to force EVERY quote at index 0 down the \"escaped\"\r\n // branch instead, since 0 is falsy, which broke parsing of any row\r\n // whose first field is quoted (e.g. `\"a\",b`) with a spurious\r\n // ParseError.\r\n if (this._previous !== '\\\\') {\r\n this.handleQuoteNotEscaped();\r\n } else {\r\n this.handleQuoteEscaped();\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private handleQuoteEscaped() {\r\n this._cell = this._cell.slice(0, Math.max(0, this._cell.length - 1));\r\n }\r\n\r\n private handleQuoteNotEscaped() {\r\n if (this._cell.length === 0 || this._state.quoted) {\r\n this._state.quoted = !this._state.quoted;\r\n } else {\r\n throw new ParseError(this._state.line, this._state.lineOffset);\r\n }\r\n this._state.appendCell = false;\r\n }\r\n\r\n private handleFieldSeparator() {\r\n if (this._current === this._options.fieldSeparator) {\r\n if (!this._state.quoted) {\r\n this._state.appendCell = false;\r\n this._state.appendField = true;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private handleLineSeparator() {\r\n if (this._current === this._options.lineSeparator) {\r\n if (!this._state.quoted) {\r\n this._state.appendCell = false;\r\n this._state.appendField = true;\r\n this._state.appendRow = true;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private processState(): boolean {\r\n let end = false;\r\n if (this._state.appendCell) {\r\n this._cell += this._current;\r\n }\r\n\r\n if (this._state.appendField) {\r\n this.addField(this.fieldValue(this._cell), this._row, this._state);\r\n this._cell = '';\r\n }\r\n\r\n if (this._state.appendRow) {\r\n this.nextRow(this._row, this._state);\r\n this._row = [] as string[];\r\n end = true;\r\n }\r\n\r\n this._state.lineOffset++;\r\n this._state.fieldOffset++;\r\n\r\n return end;\r\n }\r\n\r\n private fieldValue(cell: string): string {\r\n return cell;\r\n }\r\n\r\n private addField<F extends string, T extends string[]>(\r\n field: F,\r\n row: T,\r\n state: State\r\n ) {\r\n row.push(this._options.trimming ? field.trim() : field);\r\n state.field++;\r\n state.fieldOffset = -1;\r\n state.appendField = false;\r\n }\r\n\r\n private nextRow<T extends string[]>(row: T, state: State) {\r\n this._lastRow = [...row];\r\n state.field = 0;\r\n state.line++;\r\n state.lineOffset = -1;\r\n state.appendRow = false;\r\n }\r\n\r\n private reset() {\r\n this._lastRow = [];\r\n this._row = [];\r\n this._cell = '';\r\n this._state = { ...CSV_INITAL_STATE };\r\n this._index = 0;\r\n this._current = '';\r\n this._previous = '';\r\n }\r\n}\r\n","import { Thesaurus, ThesaurusEntry } from '@myrmidon/cadmus-core';\r\nimport { CsvReader, CsvReaderOptions } from './csv-reader';\r\n\r\n/**\r\n * CSV thesaurus reader. This reads any number of thesauri from a CSV text.\r\n * By convention, the CSV has column 1=ID and column 2=value for each\r\n * thesaurus entry. Each thesaurus is started by a row having in the ID\r\n * the thesaurus ID and an empty value.\r\n * If a thesaurus ID is just an alias, the value starts with an equal sign\r\n * (e.g. \"biblio-languages,=languages\") and has no other entries.\r\n */\r\nexport class CsvThesaurusReader {\r\n private readonly _csvReader: CsvReader;\r\n private _id?: string;\r\n private _targetId?: string;\r\n private _entries: ThesaurusEntry[];\r\n private _eof: boolean | undefined;\r\n\r\n constructor(text: string, options?: CsvReaderOptions) {\r\n this._csvReader = new CsvReader(text, options);\r\n this._entries = [];\r\n }\r\n\r\n private parseLanguage(id: string): string {\r\n const i = id.lastIndexOf('@');\r\n return i > -1 ? id.substring(i + 1) : 'en';\r\n }\r\n\r\n private getThesaurus(): Thesaurus | null {\r\n if (!this._id) {\r\n return null;\r\n }\r\n return {\r\n id: this._id,\r\n language: this.parseLanguage(this._id),\r\n targetId: this._targetId,\r\n entries: this._targetId ? undefined : [...this._entries],\r\n };\r\n }\r\n\r\n private reset(): void {\r\n this._id = undefined;\r\n this._targetId = undefined;\r\n this._entries.length = 0;\r\n }\r\n\r\n /**\r\n * Read the next thesaurus if any.\r\n *\r\n * @returns Thesaurus or null if end of CSV text reached.\r\n */\r\n public read(): Thesaurus | null {\r\n if (this._eof) {\r\n return null;\r\n }\r\n\r\n while (true) {\r\n // read the next row\r\n const row = this._csvReader.read();\r\n // if no more rows, ret the last thesaurus if any\r\n if (!row) {\r\n this._eof = true;\r\n const last = this.getThesaurus();\r\n this.reset();\r\n return last;\r\n }\r\n\r\n // an empty value starts a new thesaurus\r\n if (!row[1]) {\r\n const prev = this.getThesaurus();\r\n this.reset();\r\n this._id = row[0];\r\n // return the previous thesaurus if any\r\n if (prev) {\r\n return prev;\r\n }\r\n } else if (row[1].startsWith('=') && row[1].length > 1) {\r\n // a value starting with = is the alias target\r\n const prev = this.getThesaurus();\r\n this.reset();\r\n this._id = row[0];\r\n this._targetId = row[1].substring(1);\r\n // return the previous thesaurus if any\r\n if (prev) {\r\n return prev;\r\n }\r\n } else {\r\n this._entries.push({\r\n id: row[0],\r\n value: row[1],\r\n });\r\n }\r\n }\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\n/**\r\n * A generic group of items under a group key.\r\n */\r\nexport interface KeyedGroup<T> {\r\n key: string;\r\n items: T[];\r\n}\r\n\r\n/**\r\n * Utility functions for Cadmus profile data.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ProfileUtilService {\r\n constructor() {}\r\n\r\n /**\r\n * Group an array of objects by 1 or more of its string properties.\r\n *\r\n * @param arr The array of objects to group.\r\n * @param keys The keys to be used in grouping objects. It is assumed\r\n * that such keys are all string properties.\r\n * @returns An object where each property is a key with value equal\r\n * to an array of items.\r\n */\r\n public groupIntoObject<T>(\r\n arr: T[],\r\n keys: (keyof T)[]\r\n ): { [key: string]: T[] } {\r\n // https://gist.github.com/robmathers/1830ce09695f759bf2c4df15c29dd22d\r\n return arr.reduce((storage, item) => {\r\n const compositeKey = keys.map((key) => `${item[key]}`).join(':');\r\n if (storage[compositeKey]) {\r\n storage[compositeKey].push(item);\r\n } else {\r\n storage[compositeKey] = [item];\r\n }\r\n return storage;\r\n }, {} as { [key: string]: T[] });\r\n }\r\n\r\n /**\r\n * Group an array of objects by 1 or more of its string properties,\r\n * storing the result into an array of KeyedGroup<T>.\r\n *\r\n * @param arr The array of objects to group.\r\n * @param keys The keys to be used in grouping objects. It is assumed\r\n * that such keys are all string properties.\r\n * @returns An array of KeyedGroup<T>.\r\n */\r\n public groupIntoKeyedGroups<T>(arr: T[], keys: (keyof T)[]): KeyedGroup<T>[] {\r\n let storage = new Map<string, T[]>();\r\n\r\n storage = arr.reduce((storage, item) => {\r\n const compositeKey = keys.map((key) => `${item[key]}`).join(':');\r\n\r\n if (storage.has(compositeKey)) {\r\n storage.set(compositeKey, [...(storage.get(compositeKey) || []), item]);\r\n } else {\r\n storage.set(compositeKey, [item]);\r\n }\r\n return storage;\r\n }, storage);\r\n\r\n const groups: KeyedGroup<T>[] = [];\r\n const sortedKeys: string[] = [...storage.keys()].sort();\r\n for (let key of sortedKeys) {\r\n groups.push({\r\n key: key,\r\n items: storage.get(key) as T[],\r\n });\r\n }\r\n return groups;\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\n/**\r\n * Service to let user download a text file generated into a string.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TextToFileService {\r\n constructor() {}\r\n\r\n /**\r\n * Save the specified text into a file.\r\n *\r\n * @param text The text content to be saved.\r\n * @param name The file name.\r\n * @param contentType The content type.\r\n */\r\n public saveToFile(\r\n text: string,\r\n name: string,\r\n contentType = 'text/plain'\r\n ): void {\r\n // https://robkendal.co.uk/blog/2020-04-17-saving-text-to-client-side-file-using-vanilla-js\r\n const a = document.createElement('a');\r\n const file = new Blob([text], { type: contentType });\r\n\r\n a.href = URL.createObjectURL(file);\r\n a.download = name;\r\n a.click();\r\n\r\n URL.revokeObjectURL(a.href);\r\n }\r\n}\r\n","/*\r\n * Public API Surface of cadmus-profile-core\r\n */\r\n\r\nexport * from './lib/services/csv-reader';\r\nexport * from './lib/services/csv-thesaurus-reader';\r\nexport * from './lib/services/profile-util.service';\r\nexport * from './lib/services/text-to-file.service';\r\nexport * from './lib/profile-models';\r\n\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAUA,MAAM,eAAe,GAAG;AACtB,IAAA,cAAc,EAAE,GAAG;AACnB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,KAAK,EAAE,GAAG;AACV,IAAA,QAAQ,EAAE,IAAI;CACf;AAaD,MAAM,gBAAgB,GAAG;AACvB,IAAA,KAAK,EAAE,CAAC;AACR,IAAA,WAAW,EAAE,CAAC;AACd,IAAA,IAAI,EAAE,CAAC;AACP,IAAA,UAAU,EAAE,CAAC;AACb,IA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GAAG,IAAI;QACjB,CAAC,CAAC,KAAK,EAAE;AAET,QAAA,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7B;uGAxBW,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAjB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,cAFhB,MAAM,EAAA,CAAA;;2FAEP,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAH7B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACPD;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"myrmidon-cadmus-profile-core.mjs","names":[],"sources":["../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/csv-reader.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/csv-thesaurus-reader.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/profile-util.service.ts","../../../../projects/myrmidon/cadmus-profile-core/src/lib/services/text-to-file.service.ts"],"sourcesContent":["/**\r\n * Options for CsvReader.\r\n */\r\nexport interface CsvReaderOptions {\r\n fieldSeparator?: string;\r\n lineSeparator?: string;\r\n quote?: string;\r\n trimming?: boolean;\r\n}\r\n\r\nconst DEFAULT_OPTIONS = {\r\n fieldSeparator: ',',\r\n lineSeparator: '\\n',\r\n quote: '\"',\r\n trimming: true,\r\n};\r\n\r\ninterface State {\r\n appendCell: boolean;\r\n appendField: boolean;\r\n appendRow: boolean;\r\n field: number;\r\n fieldOffset: number;\r\n line: number;\r\n lineOffset: number;\r\n quoted: boolean;\r\n}\r\n\r\nconst CSV_INITAL_STATE = {\r\n field: 0,\r\n fieldOffset: 0,\r\n line: 0,\r\n lineOffset: 0,\r\n quoted: false,\r\n appendCell: false,\r\n appendField: false,\r\n appendRow: false,\r\n} as State;\r\n\r\nclass ParseError extends Error {\r\n public constructor(line: number, column: number) {\r\n super(`Invalid CSV at ${line}:${column}`);\r\n }\r\n}\r\n\r\n/**\r\n * CSV text reader.\r\n * Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.\r\n */\r\nexport class CsvReader {\r\n private readonly _text: string;\r\n private _lastRow = [] as string[];\r\n private _row = [] as string[];\r\n private _cell = '';\r\n private _options = DEFAULT_OPTIONS;\r\n private _state = { ...CSV_INITAL_STATE };\r\n private _index = 0;\r\n private _current = '';\r\n private _previous = '';\r\n\r\n constructor(text: string, options?: CsvReaderOptions) {\r\n this._text = text;\r\n this._options = Object.assign({}, DEFAULT_OPTIONS, options || {});\r\n this.reset();\r\n }\r\n\r\n /**\r\n * Read the next row from the CSV text.\r\n *\r\n * @param text - CSV text\r\n * @returns array of fields, each being an array of strings.\r\n * @throws Error on parse error\r\n */\r\n public read(): readonly string[] | null {\r\n while (this._index < this._text.length) {\r\n this._state.appendCell = true;\r\n this._previous = this._current;\r\n this._current = this._text[this._index];\r\n if (this.handleNext()) {\r\n this._index++;\r\n return this._lastRow;\r\n }\r\n this._index++;\r\n }\r\n\r\n if (this._row.length > 0) {\r\n this.addField(this.fieldValue(this._cell), this._row, this._state);\r\n this.nextRow(this._row, this._state);\r\n this._row.length = 0;\r\n return this._lastRow;\r\n }\r\n\r\n return null;\r\n }\r\n\r\n private handleNext(): boolean {\r\n this.handleQuote() ||\r\n this.handleFieldSeparator() ||\r\n this.handleLineSeparator();\r\n return this.processState();\r\n }\r\n\r\n private handleQuote() {\r\n if (this._current === this._options.quote) {\r\n // a quote is \"escaped\" (a literal quote character inside a quoted\r\n // field) only when preceded by a backslash. _previous starts as ''\r\n // (never '\\\\'), so this already correctly treats a quote at index 0\r\n // as unescaped without needing an extra `this._index &&` guard - that\r\n // guard used to force EVERY quote at index 0 down the \"escaped\"\r\n // branch instead, since 0 is falsy, which broke parsing of any row\r\n // whose first field is quoted (e.g. `\"a\",b`) with a spurious\r\n // ParseError.\r\n if (this._previous !== '\\\\') {\r\n this.handleQuoteNotEscaped();\r\n } else {\r\n this.handleQuoteEscaped();\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private handleQuoteEscaped() {\r\n this._cell = this._cell.slice(0, Math.max(0, this._cell.length - 1));\r\n }\r\n\r\n private handleQuoteNotEscaped() {\r\n if (this._cell.length === 0 || this._state.quoted) {\r\n this._state.quoted = !this._state.quoted;\r\n } else {\r\n throw new ParseError(this._state.line, this._state.lineOffset);\r\n }\r\n this._state.appendCell = false;\r\n }\r\n\r\n private handleFieldSeparator() {\r\n if (this._current === this._options.fieldSeparator) {\r\n if (!this._state.quoted) {\r\n this._state.appendCell = false;\r\n this._state.appendField = true;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private handleLineSeparator() {\r\n if (this._current === this._options.lineSeparator) {\r\n if (!this._state.quoted) {\r\n this._state.appendCell = false;\r\n this._state.appendField = true;\r\n this._state.appendRow = true;\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n private processState(): boolean {\r\n let end = false;\r\n if (this._state.appendCell) {\r\n this._cell += this._current;\r\n }\r\n\r\n if (this._state.appendField) {\r\n this.addField(this.fieldValue(this._cell), this._row, this._state);\r\n this._cell = '';\r\n }\r\n\r\n if (this._state.appendRow) {\r\n this.nextRow(this._row, this._state);\r\n this._row = [] as string[];\r\n end = true;\r\n }\r\n\r\n this._state.lineOffset++;\r\n this._state.fieldOffset++;\r\n\r\n return end;\r\n }\r\n\r\n private fieldValue(cell: string): string {\r\n return cell;\r\n }\r\n\r\n private addField<F extends string, T extends string[]>(\r\n field: F,\r\n row: T,\r\n state: State\r\n ) {\r\n row.push(this._options.trimming ? field.trim() : field);\r\n state.field++;\r\n state.fieldOffset = -1;\r\n state.appendField = false;\r\n }\r\n\r\n private nextRow<T extends string[]>(row: T, state: State) {\r\n this._lastRow = [...row];\r\n state.field = 0;\r\n state.line++;\r\n state.lineOffset = -1;\r\n state.appendRow = false;\r\n }\r\n\r\n private reset() {\r\n this._lastRow = [];\r\n this._row = [];\r\n this._cell = '';\r\n this._state = { ...CSV_INITAL_STATE };\r\n this._index = 0;\r\n this._current = '';\r\n this._previous = '';\r\n }\r\n}\r\n","import { Thesaurus, ThesaurusEntry } from '@myrmidon/cadmus-core';\r\nimport { CsvReader, CsvReaderOptions } from './csv-reader';\r\n\r\n/**\r\n * CSV thesaurus reader. This reads any number of thesauri from a CSV text.\r\n * By convention, the CSV has column 1=ID and column 2=value for each\r\n * thesaurus entry. Each thesaurus is started by a row having in the ID\r\n * the thesaurus ID and an empty value.\r\n * If a thesaurus ID is just an alias, the value starts with an equal sign\r\n * (e.g. \"biblio-languages,=languages\") and has no other entries.\r\n */\r\nexport class CsvThesaurusReader {\r\n private readonly _csvReader: CsvReader;\r\n private _id?: string;\r\n private _targetId?: string;\r\n private _entries: ThesaurusEntry[];\r\n private _eof: boolean | undefined;\r\n\r\n constructor(text: string, options?: CsvReaderOptions) {\r\n this._csvReader = new CsvReader(text, options);\r\n this._entries = [];\r\n }\r\n\r\n private parseLanguage(id: string): string {\r\n const i = id.lastIndexOf('@');\r\n return i > -1 ? id.substring(i + 1) : 'en';\r\n }\r\n\r\n private getThesaurus(): Thesaurus | null {\r\n if (!this._id) {\r\n return null;\r\n }\r\n return {\r\n id: this._id,\r\n language: this.parseLanguage(this._id),\r\n targetId: this._targetId,\r\n entries: this._targetId ? undefined : [...this._entries],\r\n };\r\n }\r\n\r\n private reset(): void {\r\n this._id = undefined;\r\n this._targetId = undefined;\r\n this._entries.length = 0;\r\n }\r\n\r\n /**\r\n * Read the next thesaurus if any.\r\n *\r\n * @returns Thesaurus or null if end of CSV text reached.\r\n */\r\n public read(): Thesaurus | null {\r\n if (this._eof) {\r\n return null;\r\n }\r\n\r\n while (true) {\r\n // read the next row\r\n const row = this._csvReader.read();\r\n // if no more rows, ret the last thesaurus if any\r\n if (!row) {\r\n this._eof = true;\r\n const last = this.getThesaurus();\r\n this.reset();\r\n return last;\r\n }\r\n\r\n // an empty value starts a new thesaurus\r\n if (!row[1]) {\r\n const prev = this.getThesaurus();\r\n this.reset();\r\n this._id = row[0];\r\n // return the previous thesaurus if any\r\n if (prev) {\r\n return prev;\r\n }\r\n } else if (row[1].startsWith('=') && row[1].length > 1) {\r\n // a value starting with = is the alias target\r\n const prev = this.getThesaurus();\r\n this.reset();\r\n this._id = row[0];\r\n this._targetId = row[1].substring(1);\r\n // return the previous thesaurus if any\r\n if (prev) {\r\n return prev;\r\n }\r\n } else {\r\n this._entries.push({\r\n id: row[0],\r\n value: row[1],\r\n });\r\n }\r\n }\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\n/**\r\n * A generic group of items under a group key.\r\n */\r\nexport interface KeyedGroup<T> {\r\n key: string;\r\n items: T[];\r\n}\r\n\r\n/**\r\n * Utility functions for Cadmus profile data.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class ProfileUtilService {\r\n constructor() {}\r\n\r\n /**\r\n * Group an array of objects by 1 or more of its string properties.\r\n *\r\n * @param arr The array of objects to group.\r\n * @param keys The keys to be used in grouping objects. It is assumed\r\n * that such keys are all string properties.\r\n * @returns An object where each property is a key with value equal\r\n * to an array of items.\r\n */\r\n public groupIntoObject<T>(\r\n arr: T[],\r\n keys: (keyof T)[]\r\n ): { [key: string]: T[] } {\r\n // https://gist.github.com/robmathers/1830ce09695f759bf2c4df15c29dd22d\r\n return arr.reduce((storage, item) => {\r\n const compositeKey = keys.map((key) => `${item[key]}`).join(':');\r\n if (storage[compositeKey]) {\r\n storage[compositeKey].push(item);\r\n } else {\r\n storage[compositeKey] = [item];\r\n }\r\n return storage;\r\n }, {} as { [key: string]: T[] });\r\n }\r\n\r\n /**\r\n * Group an array of objects by 1 or more of its string properties,\r\n * storing the result into an array of KeyedGroup<T>.\r\n *\r\n * @param arr The array of objects to group.\r\n * @param keys The keys to be used in grouping objects. It is assumed\r\n * that such keys are all string properties.\r\n * @returns An array of KeyedGroup<T>.\r\n */\r\n public groupIntoKeyedGroups<T>(arr: T[], keys: (keyof T)[]): KeyedGroup<T>[] {\r\n let storage = new Map<string, T[]>();\r\n\r\n storage = arr.reduce((storage, item) => {\r\n const compositeKey = keys.map((key) => `${item[key]}`).join(':');\r\n\r\n if (storage.has(compositeKey)) {\r\n storage.set(compositeKey, [...(storage.get(compositeKey) || []), item]);\r\n } else {\r\n storage.set(compositeKey, [item]);\r\n }\r\n return storage;\r\n }, storage);\r\n\r\n const groups: KeyedGroup<T>[] = [];\r\n const sortedKeys: string[] = [...storage.keys()].sort();\r\n for (let key of sortedKeys) {\r\n groups.push({\r\n key: key,\r\n items: storage.get(key) as T[],\r\n });\r\n }\r\n return groups;\r\n }\r\n}\r\n","import { Injectable } from '@angular/core';\r\n\r\n/**\r\n * Service to let user download a text file generated into a string.\r\n */\r\n@Injectable({\r\n providedIn: 'root',\r\n})\r\nexport class TextToFileService {\r\n constructor() {}\r\n\r\n /**\r\n * Save the specified text into a file.\r\n *\r\n * @param text The text content to be saved.\r\n * @param name The file name.\r\n * @param contentType The content type.\r\n */\r\n public saveToFile(\r\n text: string,\r\n name: string,\r\n contentType = 'text/plain'\r\n ): void {\r\n // https://robkendal.co.uk/blog/2020-04-17-saving-text-to-client-side-file-using-vanilla-js\r\n const a = document.createElement('a');\r\n const file = new Blob([text], { type: contentType });\r\n\r\n a.href = URL.createObjectURL(file);\r\n a.download = name;\r\n a.click();\r\n\r\n URL.revokeObjectURL(a.href);\r\n }\r\n}\r\n"],"mappings":";;AAUA,MAAM,kBAAkB;CACtB,gBAAgB;CAChB,eAAe;CACf,OAAO;CACP,UAAU;AACX;AAaD,MAAM,mBAAmB;CACvB,OAAO;CACP,aAAa;CACb,MAAM;CACN,YAAY;CACZ,QAAQ;CACR,YAAY;CACZ,aAAa;CACb,WAAW;AACH;AAEV,IAAM,aA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;EAAA,UAAA;EAAA,MAAA;EAAkB,YAFjB;CAAM,CAAA;;AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAkB,YAAA,CAAA;EAH9B,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA;;;;ACPD,IAAa,oBAAb,MAAa,kBAAiB;CAC5B,cAAA,CAAe;CASR,WACL,MACA,MACA,cAAc,cAAY;EAG1B,MAAM,IAAI,SAAS,cAAc,GAAG;EACpC,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAM,YAAW,CAAE;EAEnD,EAAE,OAAO,IAAI,gBAAgB,IAAI;EACjC,EAAE,WAAW;EACb,EAAE,MAAK;EAEP,IAAI,gBAAgB,EAAE,IAAI;CAC5B;CAxBW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAiB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAjB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAiB,YAFhB;CAAM,CAAA;;AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAiB,YAAA,CAAA;EAH7B,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myrmidon/cadmus-profile-core",
3
- "version": "13.0.1",
3
+ "version": "20.0.0",
4
4
  "description": "Cadmus - profile services.",
5
5
  "keywords": [
6
6
  "Cadmus"
@@ -14,8 +14,9 @@
14
14
  "name": "Daniele Fusi"
15
15
  },
16
16
  "peerDependencies": {
17
- "@angular/common": "^22.0.0",
18
- "@angular/core": "^22.0.0"
17
+ "@angular/common": "^22.2.1",
18
+ "@angular/core": "^22.2.1",
19
+ "@myrmidon/cadmus-core": "^20.0.0"
19
20
  },
20
21
  "dependencies": {
21
22
  "tslib": "^2.3.0"
@@ -1,51 +1,49 @@
1
- import { Thesaurus } from '@myrmidon/cadmus-core';
2
- import * as i0 from '@angular/core';
3
-
1
+ import { Thesaurus } from "@myrmidon/cadmus-core";
2
+ import * as i0 from "@angular/core";
4
3
  /**
5
4
  * Options for CsvReader.
6
5
  */
7
- interface CsvReaderOptions {
8
- fieldSeparator?: string;
9
- lineSeparator?: string;
10
- quote?: string;
11
- trimming?: boolean;
6
+ export interface CsvReaderOptions {
7
+ fieldSeparator?: string;
8
+ lineSeparator?: string;
9
+ quote?: string;
10
+ trimming?: boolean;
12
11
  }
13
12
  /**
14
13
  * CSV text reader.
15
14
  * Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.
16
15
  */
17
- declare class CsvReader {
18
- private readonly _text;
19
- private _lastRow;
20
- private _row;
21
- private _cell;
22
- private _options;
23
- private _state;
24
- private _index;
25
- private _current;
26
- private _previous;
27
- constructor(text: string, options?: CsvReaderOptions);
28
- /**
29
- * Read the next row from the CSV text.
30
- *
31
- * @param text - CSV text
32
- * @returns array of fields, each being an array of strings.
33
- * @throws Error on parse error
34
- */
35
- read(): readonly string[] | null;
36
- private handleNext;
37
- private handleQuote;
38
- private handleQuoteEscaped;
39
- private handleQuoteNotEscaped;
40
- private handleFieldSeparator;
41
- private handleLineSeparator;
42
- private processState;
43
- private fieldValue;
44
- private addField;
45
- private nextRow;
46
- private reset;
16
+ export declare class CsvReader {
17
+ private readonly _text;
18
+ private _lastRow;
19
+ private _row;
20
+ private _cell;
21
+ private _options;
22
+ private _state;
23
+ private _index;
24
+ private _current;
25
+ private _previous;
26
+ constructor(text: string, options?: CsvReaderOptions);
27
+ /**
28
+ * Read the next row from the CSV text.
29
+ *
30
+ * @param text - CSV text
31
+ * @returns array of fields, each being an array of strings.
32
+ * @throws Error on parse error
33
+ */
34
+ read(): readonly string[] | null;
35
+ private handleNext;
36
+ private handleQuote;
37
+ private handleQuoteEscaped;
38
+ private handleQuoteNotEscaped;
39
+ private handleFieldSeparator;
40
+ private handleLineSeparator;
41
+ private processState;
42
+ private fieldValue;
43
+ private addField;
44
+ private nextRow;
45
+ private reset;
47
46
  }
48
-
49
47
  /**
50
48
  * CSV thesaurus reader. This reads any number of thesauri from a CSV text.
51
49
  * By convention, the CSV has column 1=ID and column 2=value for each
@@ -54,87 +52,81 @@ declare class CsvReader {
54
52
  * If a thesaurus ID is just an alias, the value starts with an equal sign
55
53
  * (e.g. "biblio-languages,=languages") and has no other entries.
56
54
  */
57
- declare class CsvThesaurusReader {
58
- private readonly _csvReader;
59
- private _id?;
60
- private _targetId?;
61
- private _entries;
62
- private _eof;
63
- constructor(text: string, options?: CsvReaderOptions);
64
- private parseLanguage;
65
- private getThesaurus;
66
- private reset;
67
- /**
68
- * Read the next thesaurus if any.
69
- *
70
- * @returns Thesaurus or null if end of CSV text reached.
71
- */
72
- read(): Thesaurus | null;
55
+ export declare class CsvThesaurusReader {
56
+ private readonly _csvReader;
57
+ private _id?;
58
+ private _targetId?;
59
+ private _entries;
60
+ private _eof;
61
+ constructor(text: string, options?: CsvReaderOptions);
62
+ private parseLanguage;
63
+ private getThesaurus;
64
+ private reset;
65
+ /**
66
+ * Read the next thesaurus if any.
67
+ *
68
+ * @returns Thesaurus or null if end of CSV text reached.
69
+ */
70
+ read(): Thesaurus | null;
73
71
  }
74
-
75
72
  /**
76
73
  * A generic group of items under a group key.
77
74
  */
78
- interface KeyedGroup<T> {
79
- key: string;
80
- items: T[];
75
+ export interface KeyedGroup<T> {
76
+ key: string;
77
+ items: T[];
81
78
  }
82
79
  /**
83
80
  * Utility functions for Cadmus profile data.
84
81
  */
85
- declare class ProfileUtilService {
86
- constructor();
87
- /**
88
- * Group an array of objects by 1 or more of its string properties.
89
- *
90
- * @param arr The array of objects to group.
91
- * @param keys The keys to be used in grouping objects. It is assumed
92
- * that such keys are all string properties.
93
- * @returns An object where each property is a key with value equal
94
- * to an array of items.
95
- */
96
- groupIntoObject<T>(arr: T[], keys: (keyof T)[]): {
97
- [key: string]: T[];
98
- };
99
- /**
100
- * Group an array of objects by 1 or more of its string properties,
101
- * storing the result into an array of KeyedGroup<T>.
102
- *
103
- * @param arr The array of objects to group.
104
- * @param keys The keys to be used in grouping objects. It is assumed
105
- * that such keys are all string properties.
106
- * @returns An array of KeyedGroup<T>.
107
- */
108
- groupIntoKeyedGroups<T>(arr: T[], keys: (keyof T)[]): KeyedGroup<T>[];
109
- static ɵfac: i0.ɵɵFactoryDeclaration<ProfileUtilService, never>;
110
- static ɵprov: i0.ɵɵInjectableDeclaration<ProfileUtilService>;
82
+ export declare class ProfileUtilService {
83
+ constructor();
84
+ /**
85
+ * Group an array of objects by 1 or more of its string properties.
86
+ *
87
+ * @param arr The array of objects to group.
88
+ * @param keys The keys to be used in grouping objects. It is assumed
89
+ * that such keys are all string properties.
90
+ * @returns An object where each property is a key with value equal
91
+ * to an array of items.
92
+ */
93
+ groupIntoObject<T>(arr: T[], keys: (keyof T)[]): {
94
+ [key: string]: T[];
95
+ };
96
+ /**
97
+ * Group an array of objects by 1 or more of its string properties,
98
+ * storing the result into an array of KeyedGroup<T>.
99
+ *
100
+ * @param arr The array of objects to group.
101
+ * @param keys The keys to be used in grouping objects. It is assumed
102
+ * that such keys are all string properties.
103
+ * @returns An array of KeyedGroup<T>.
104
+ */
105
+ groupIntoKeyedGroups<T>(arr: T[], keys: (keyof T)[]): KeyedGroup<T>[];
106
+ static ɵfac: i0.ɵɵFactoryDeclaration<ProfileUtilService, never>;
107
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
111
108
  }
112
-
113
109
  /**
114
110
  * Service to let user download a text file generated into a string.
115
111
  */
116
- declare class TextToFileService {
117
- constructor();
118
- /**
119
- * Save the specified text into a file.
120
- *
121
- * @param text The text content to be saved.
122
- * @param name The file name.
123
- * @param contentType The content type.
124
- */
125
- saveToFile(text: string, name: string, contentType?: string): void;
126
- static ɵfac: i0.ɵɵFactoryDeclaration<TextToFileService, never>;
127
- static ɵprov: i0.ɵɵInjectableDeclaration<TextToFileService>;
112
+ export declare class TextToFileService {
113
+ constructor();
114
+ /**
115
+ * Save the specified text into a file.
116
+ *
117
+ * @param text The text content to be saved.
118
+ * @param name The file name.
119
+ * @param contentType The content type.
120
+ */
121
+ saveToFile(text: string, name: string, contentType?: string): void;
122
+ static ɵfac: i0.ɵɵFactoryDeclaration<TextToFileService, never>;
123
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
128
124
  }
129
-
130
125
  /**
131
126
  * A generic signal used by child components to emit
132
127
  * events signaling some action to be taken.
133
128
  */
134
- interface ComponentSignal<T> {
135
- id: string;
136
- payload?: T;
137
- }
138
-
139
- export { CsvReader, CsvThesaurusReader, ProfileUtilService, TextToFileService };
140
- export type { ComponentSignal, CsvReaderOptions, KeyedGroup };
129
+ export interface ComponentSignal<T> {
130
+ id: string;
131
+ payload?: T;
132
+ }