@myrmidon/cadmus-profile-core 10.0.0 → 12.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.
- package/README.md +7 -24
- package/fesm2022/myrmidon-cadmus-profile-core.mjs +22 -30
- package/fesm2022/myrmidon-cadmus-profile-core.mjs.map +1 -1
- package/index.d.ts +138 -3
- package/package.json +3 -3
- package/lib/cadmus-profile-core.module.d.ts +0 -6
- package/lib/profile-models.d.ts +0 -8
- package/lib/services/csv-reader.d.ts +0 -44
- package/lib/services/csv-thesaurus-reader.d.ts +0 -27
- package/lib/services/profile-util.service.d.ts +0 -38
- package/lib/services/text-to-file.service.d.ts +0 -17
- package/public-api.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
# CadmusProfileCore
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project cadmus-profile-core` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
-
|
|
10
|
-
## Build
|
|
11
|
-
|
|
12
|
-
Run `ng build cadmus-profile-core` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
-
|
|
14
|
-
## Publishing
|
|
15
|
-
|
|
16
|
-
After building your library with `ng build cadmus-profile-core`, go to the dist folder `cd dist/cadmus-profile-core` and run `npm publish`.
|
|
17
|
-
|
|
18
|
-
## Running unit tests
|
|
19
|
-
|
|
20
|
-
Run `ng test cadmus-profile-core` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
-
|
|
22
|
-
## Further help
|
|
23
|
-
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
|
1
|
+
# CadmusProfileCore
|
|
2
|
+
|
|
3
|
+
- 📦 `@myrmidon/cadmus-profile-core`
|
|
4
|
+
|
|
5
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.0.0.
|
|
6
|
+
|
|
7
|
+
This library contains services and models for managing Cadmus profiles (mostly thesauri).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_OPTIONS = {
|
|
5
5
|
fieldSeparator: ',',
|
|
@@ -27,15 +27,16 @@ class ParseError extends Error {
|
|
|
27
27
|
* Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.
|
|
28
28
|
*/
|
|
29
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 = '';
|
|
30
39
|
constructor(text, options) {
|
|
31
|
-
this._lastRow = [];
|
|
32
|
-
this._row = [];
|
|
33
|
-
this._cell = '';
|
|
34
|
-
this._options = DEFAULT_OPTIONS;
|
|
35
|
-
this._state = { ...CSV_INITAL_STATE };
|
|
36
|
-
this._index = 0;
|
|
37
|
-
this._current = '';
|
|
38
|
-
this._previous = '';
|
|
39
40
|
this._text = text;
|
|
40
41
|
this._options = Object.assign({}, DEFAULT_OPTIONS, options || {});
|
|
41
42
|
this.reset();
|
|
@@ -171,6 +172,11 @@ class CsvReader {
|
|
|
171
172
|
* (e.g. "biblio-languages,=languages") and has no other entries.
|
|
172
173
|
*/
|
|
173
174
|
class CsvThesaurusReader {
|
|
175
|
+
_csvReader;
|
|
176
|
+
_id;
|
|
177
|
+
_targetId;
|
|
178
|
+
_entries;
|
|
179
|
+
_eof;
|
|
174
180
|
constructor(text, options) {
|
|
175
181
|
this._csvReader = new CsvReader(text, options);
|
|
176
182
|
this._entries = [];
|
|
@@ -303,10 +309,10 @@ class ProfileUtilService {
|
|
|
303
309
|
}
|
|
304
310
|
return groups;
|
|
305
311
|
}
|
|
306
|
-
static
|
|
307
|
-
static
|
|
312
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: ProfileUtilService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
313
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: ProfileUtilService, providedIn: 'root' });
|
|
308
314
|
}
|
|
309
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
315
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: ProfileUtilService, decorators: [{
|
|
310
316
|
type: Injectable,
|
|
311
317
|
args: [{
|
|
312
318
|
providedIn: 'root',
|
|
@@ -334,30 +340,16 @@ class TextToFileService {
|
|
|
334
340
|
a.click();
|
|
335
341
|
URL.revokeObjectURL(a.href);
|
|
336
342
|
}
|
|
337
|
-
static
|
|
338
|
-
static
|
|
343
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: TextToFileService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
344
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: TextToFileService, providedIn: 'root' });
|
|
339
345
|
}
|
|
340
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
346
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: TextToFileService, decorators: [{
|
|
341
347
|
type: Injectable,
|
|
342
348
|
args: [{
|
|
343
349
|
providedIn: 'root',
|
|
344
350
|
}]
|
|
345
351
|
}], ctorParameters: () => [] });
|
|
346
352
|
|
|
347
|
-
class CadmusProfileCoreModule {
|
|
348
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.1", ngImport: i0, type: CadmusProfileCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
349
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.1", ngImport: i0, type: CadmusProfileCoreModule }); }
|
|
350
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.1", ngImport: i0, type: CadmusProfileCoreModule }); }
|
|
351
|
-
}
|
|
352
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.1", ngImport: i0, type: CadmusProfileCoreModule, decorators: [{
|
|
353
|
-
type: NgModule,
|
|
354
|
-
args: [{
|
|
355
|
-
declarations: [],
|
|
356
|
-
imports: [],
|
|
357
|
-
exports: [],
|
|
358
|
-
}]
|
|
359
|
-
}] });
|
|
360
|
-
|
|
361
353
|
/*
|
|
362
354
|
* Public API Surface of cadmus-profile-core
|
|
363
355
|
*/
|
|
@@ -366,5 +358,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.1", ngImpor
|
|
|
366
358
|
* Generated bundle index. Do not edit.
|
|
367
359
|
*/
|
|
368
360
|
|
|
369
|
-
export {
|
|
361
|
+
export { CsvReader, CsvThesaurusReader, ProfileUtilService, TextToFileService };
|
|
370
362
|
//# 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/lib/cadmus-profile-core.module.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 if (this._index && 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","import { NgModule } from '@angular/core';\r\n\r\n@NgModule({\r\n declarations: [],\r\n imports: [],\r\n exports: [],\r\n})\r\nexport class CadmusProfileCoreModule {}\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\nexport * from './lib/cadmus-profile-core.module';\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,IAAA,MAAM,EAAE,KAAK;AACb,IAAA,UAAU,EAAE,KAAK;AACjB,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,SAAS,EAAE,KAAK;CACR;AAEV,MAAM,UAAW,SAAQ,KAAK,CAAA;IAC5B,WAAmB,CAAA,IAAY,EAAE,MAAc,EAAA;AAC7C,QAAA,KAAK,CAAC,CAAkB,eAAA,EAAA,IAAI,IAAI,MAAM,CAAA,CAAE,CAAC;;AAE5C;AAED;;;AAGG;MACU,SAAS,CAAA;IAWpB,WAAY,CAAA,IAAY,EAAE,OAA0B,EAAA;QAT5C,IAAQ,CAAA,QAAA,GAAG,EAAc;QACzB,IAAI,CAAA,IAAA,GAAG,EAAc;QACrB,IAAK,CAAA,KAAA,GAAG,EAAE;QACV,IAAQ,CA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B,EAAA,CAAA,CAAA;+GAAvB,uBAAuB,EAAA,CAAA,CAAA;;2FAAvB,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBALnC,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EAAE;AACX,oBAAA,OAAO,EAAE,EAAE;AACZ,iBAAA;;;ACND;;AAEG;;ACFH;;AAEG;;;;"}
|
|
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 if (this._index && 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,IAAA,MAAM,EAAE,KAAK;AACb,IAAA,UAAU,EAAE,KAAK;AACjB,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,SAAS,EAAE,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,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;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,140 @@
|
|
|
1
|
+
import { Thesaurus } from '@myrmidon/cadmus-core';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
5
|
+
* Options for CsvReader.
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
interface CsvReaderOptions {
|
|
8
|
+
fieldSeparator?: string;
|
|
9
|
+
lineSeparator?: string;
|
|
10
|
+
quote?: string;
|
|
11
|
+
trimming?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* CSV text reader.
|
|
15
|
+
* Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.
|
|
16
|
+
*/
|
|
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;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* CSV thesaurus reader. This reads any number of thesauri from a CSV text.
|
|
51
|
+
* By convention, the CSV has column 1=ID and column 2=value for each
|
|
52
|
+
* thesaurus entry. Each thesaurus is started by a row having in the ID
|
|
53
|
+
* the thesaurus ID and an empty value.
|
|
54
|
+
* If a thesaurus ID is just an alias, the value starts with an equal sign
|
|
55
|
+
* (e.g. "biblio-languages,=languages") and has no other entries.
|
|
56
|
+
*/
|
|
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;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A generic group of items under a group key.
|
|
77
|
+
*/
|
|
78
|
+
interface KeyedGroup<T> {
|
|
79
|
+
key: string;
|
|
80
|
+
items: T[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Utility functions for Cadmus profile data.
|
|
84
|
+
*/
|
|
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>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Service to let user download a text file generated into a string.
|
|
115
|
+
*/
|
|
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>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A generic signal used by child components to emit
|
|
132
|
+
* events signaling some action to be taken.
|
|
133
|
+
*/
|
|
134
|
+
interface ComponentSignal<T> {
|
|
135
|
+
id: string;
|
|
136
|
+
payload?: T;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { CsvReader, CsvThesaurusReader, ProfileUtilService, TextToFileService };
|
|
140
|
+
export type { ComponentSignal, CsvReaderOptions, KeyedGroup };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrmidon/cadmus-profile-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Cadmus - profile services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Cadmus"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"name": "Daniele Fusi"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/common": "^
|
|
18
|
-
"@angular/core": "^
|
|
17
|
+
"@angular/common": "^20.0.0",
|
|
18
|
+
"@angular/core": "^20.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"tslib": "^2.3.0"
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
export declare class CadmusProfileCoreModule {
|
|
3
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CadmusProfileCoreModule, never>;
|
|
4
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<CadmusProfileCoreModule, never, never, never>;
|
|
5
|
-
static ɵinj: i0.ɵɵInjectorDeclaration<CadmusProfileCoreModule>;
|
|
6
|
-
}
|
package/lib/profile-models.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for CsvReader.
|
|
3
|
-
*/
|
|
4
|
-
export interface CsvReaderOptions {
|
|
5
|
-
fieldSeparator?: string;
|
|
6
|
-
lineSeparator?: string;
|
|
7
|
-
quote?: string;
|
|
8
|
-
trimming?: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* CSV text reader.
|
|
12
|
-
* Refactored from https://github.com/gregoranders/ts-csv/blob/master/src/index.ts.
|
|
13
|
-
*/
|
|
14
|
-
export declare class CsvReader {
|
|
15
|
-
private readonly _text;
|
|
16
|
-
private _lastRow;
|
|
17
|
-
private _row;
|
|
18
|
-
private _cell;
|
|
19
|
-
private _options;
|
|
20
|
-
private _state;
|
|
21
|
-
private _index;
|
|
22
|
-
private _current;
|
|
23
|
-
private _previous;
|
|
24
|
-
constructor(text: string, options?: CsvReaderOptions);
|
|
25
|
-
/**
|
|
26
|
-
* Read the next row from the CSV text.
|
|
27
|
-
*
|
|
28
|
-
* @param text - CSV text
|
|
29
|
-
* @returns array of fields, each being an array of strings.
|
|
30
|
-
* @throws Error on parse error
|
|
31
|
-
*/
|
|
32
|
-
read(): readonly string[] | null;
|
|
33
|
-
private handleNext;
|
|
34
|
-
private handleQuote;
|
|
35
|
-
private handleQuoteEscaped;
|
|
36
|
-
private handleQuoteNotEscaped;
|
|
37
|
-
private handleFieldSeparator;
|
|
38
|
-
private handleLineSeparator;
|
|
39
|
-
private processState;
|
|
40
|
-
private fieldValue;
|
|
41
|
-
private addField;
|
|
42
|
-
private nextRow;
|
|
43
|
-
private reset;
|
|
44
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Thesaurus } from '@myrmidon/cadmus-core';
|
|
2
|
-
import { CsvReaderOptions } from './csv-reader';
|
|
3
|
-
/**
|
|
4
|
-
* CSV thesaurus reader. This reads any number of thesauri from a CSV text.
|
|
5
|
-
* By convention, the CSV has column 1=ID and column 2=value for each
|
|
6
|
-
* thesaurus entry. Each thesaurus is started by a row having in the ID
|
|
7
|
-
* the thesaurus ID and an empty value.
|
|
8
|
-
* If a thesaurus ID is just an alias, the value starts with an equal sign
|
|
9
|
-
* (e.g. "biblio-languages,=languages") and has no other entries.
|
|
10
|
-
*/
|
|
11
|
-
export declare class CsvThesaurusReader {
|
|
12
|
-
private readonly _csvReader;
|
|
13
|
-
private _id?;
|
|
14
|
-
private _targetId?;
|
|
15
|
-
private _entries;
|
|
16
|
-
private _eof;
|
|
17
|
-
constructor(text: string, options?: CsvReaderOptions);
|
|
18
|
-
private parseLanguage;
|
|
19
|
-
private getThesaurus;
|
|
20
|
-
private reset;
|
|
21
|
-
/**
|
|
22
|
-
* Read the next thesaurus if any.
|
|
23
|
-
*
|
|
24
|
-
* @returns Thesaurus or null if end of CSV text reached.
|
|
25
|
-
*/
|
|
26
|
-
read(): Thesaurus | null;
|
|
27
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
/**
|
|
3
|
-
* A generic group of items under a group key.
|
|
4
|
-
*/
|
|
5
|
-
export interface KeyedGroup<T> {
|
|
6
|
-
key: string;
|
|
7
|
-
items: T[];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Utility functions for Cadmus profile data.
|
|
11
|
-
*/
|
|
12
|
-
export declare class ProfileUtilService {
|
|
13
|
-
constructor();
|
|
14
|
-
/**
|
|
15
|
-
* Group an array of objects by 1 or more of its string properties.
|
|
16
|
-
*
|
|
17
|
-
* @param arr The array of objects to group.
|
|
18
|
-
* @param keys The keys to be used in grouping objects. It is assumed
|
|
19
|
-
* that such keys are all string properties.
|
|
20
|
-
* @returns An object where each property is a key with value equal
|
|
21
|
-
* to an array of items.
|
|
22
|
-
*/
|
|
23
|
-
groupIntoObject<T>(arr: T[], keys: (keyof T)[]): {
|
|
24
|
-
[key: string]: T[];
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Group an array of objects by 1 or more of its string properties,
|
|
28
|
-
* storing the result into an array of KeyedGroup<T>.
|
|
29
|
-
*
|
|
30
|
-
* @param arr The array of objects to group.
|
|
31
|
-
* @param keys The keys to be used in grouping objects. It is assumed
|
|
32
|
-
* that such keys are all string properties.
|
|
33
|
-
* @returns An array of KeyedGroup<T>.
|
|
34
|
-
*/
|
|
35
|
-
groupIntoKeyedGroups<T>(arr: T[], keys: (keyof T)[]): KeyedGroup<T>[];
|
|
36
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<ProfileUtilService, never>;
|
|
37
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<ProfileUtilService>;
|
|
38
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
/**
|
|
3
|
-
* Service to let user download a text file generated into a string.
|
|
4
|
-
*/
|
|
5
|
-
export declare class TextToFileService {
|
|
6
|
-
constructor();
|
|
7
|
-
/**
|
|
8
|
-
* Save the specified text into a file.
|
|
9
|
-
*
|
|
10
|
-
* @param text The text content to be saved.
|
|
11
|
-
* @param name The file name.
|
|
12
|
-
* @param contentType The content type.
|
|
13
|
-
*/
|
|
14
|
-
saveToFile(text: string, name: string, contentType?: string): void;
|
|
15
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<TextToFileService, never>;
|
|
16
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<TextToFileService>;
|
|
17
|
-
}
|
package/public-api.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from './lib/services/csv-reader';
|
|
2
|
-
export * from './lib/services/csv-thesaurus-reader';
|
|
3
|
-
export * from './lib/services/profile-util.service';
|
|
4
|
-
export * from './lib/services/text-to-file.service';
|
|
5
|
-
export * from './lib/profile-models';
|
|
6
|
-
export * from './lib/cadmus-profile-core.module';
|