namefully 1.0.9 → 1.2.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/LICENSE +21 -674
- package/dist/example/index.js +2734 -0
- package/dist/lib/config.d.ts +121 -0
- package/dist/lib/config.js +189 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +4 -0
- package/dist/lib/constants.js +31 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/error.d.ts +172 -0
- package/dist/lib/error.js +210 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/{usecases/index.d.ts → example/example.d.ts} +0 -0
- package/dist/lib/full-name.d.ts +71 -0
- package/dist/lib/full-name.js +147 -0
- package/dist/lib/full-name.js.map +1 -0
- package/dist/lib/index.d.ts +16 -6
- package/dist/lib/index.js +29 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/name.d.ts +177 -0
- package/dist/lib/name.js +322 -0
- package/dist/lib/name.js.map +1 -0
- package/dist/lib/namefully.d.ts +303 -208
- package/dist/lib/namefully.js +603 -442
- package/dist/lib/namefully.js.map +1 -1
- package/dist/lib/parser.d.ts +46 -0
- package/dist/lib/parser.js +173 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/src/config.d.ts +121 -0
- package/dist/lib/src/constants.d.ts +4 -0
- package/dist/lib/src/error.d.ts +172 -0
- package/dist/lib/src/full-name.d.ts +71 -0
- package/dist/lib/src/index.d.ts +16 -6
- package/dist/lib/src/name.d.ts +177 -0
- package/dist/lib/src/namefully.d.ts +303 -208
- package/dist/lib/src/parser.d.ts +46 -0
- package/dist/lib/src/types.d.ts +127 -0
- package/dist/lib/src/utils.d.ts +63 -0
- package/dist/lib/src/validator.d.ts +66 -0
- package/dist/lib/types.d.ts +127 -0
- package/dist/lib/types.js +181 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +63 -0
- package/dist/lib/utils.js +138 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validator.d.ts +66 -0
- package/dist/lib/validator.js +332 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/umd/namefully.js +2191 -2111
- package/dist/umd/namefully.js.map +1 -1
- package/dist/umd/namefully.min.js +1 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +8 -20
- package/dist/umd/namefully.min.js.map +1 -1
- package/package.json +50 -53
- package/readme.md +151 -175
- package/changelog.md +0 -114
- package/dist/lib/core/constants.d.ts +0 -26
- package/dist/lib/core/constants.js +0 -42
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/index.d.ts +0 -9
- package/dist/lib/core/index.js +0 -13
- package/dist/lib/core/index.js.map +0 -1
- package/dist/lib/core/parsers/array-name.parser.d.ts +0 -42
- package/dist/lib/core/parsers/array-name.parser.js +0 -84
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/core/parsers/array-string.parser.js +0 -96
- package/dist/lib/core/parsers/array-string.parser.js.map +0 -1
- package/dist/lib/core/parsers/index.d.ts +0 -11
- package/dist/lib/core/parsers/index.js +0 -11
- package/dist/lib/core/parsers/index.js.map +0 -1
- package/dist/lib/core/parsers/nama.parser.d.ts +0 -34
- package/dist/lib/core/parsers/nama.parser.js +0 -75
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -29
- package/dist/lib/core/parsers/parser.js +0 -3
- package/dist/lib/core/parsers/parser.js.map +0 -1
- package/dist/lib/core/parsers/string.parser.d.ts +0 -61
- package/dist/lib/core/parsers/string.parser.js +0 -63
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils/utils.d.ts +0 -14
- package/dist/lib/core/utils/utils.js +0 -67
- package/dist/lib/core/utils/utils.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -91
- package/dist/lib/models/enums.js +0 -98
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -41
- package/dist/lib/models/firstname.js +0 -59
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -12
- package/dist/lib/models/index.js +0 -15
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -44
- package/dist/lib/models/lastname.js +0 -86
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -80
- package/dist/lib/models/misc.js +0 -3
- package/dist/lib/models/misc.js.map +0 -1
- package/dist/lib/models/name.d.ts +0 -48
- package/dist/lib/models/name.js +0 -72
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -23
- package/dist/lib/models/summary.js +0 -60
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/src/core/constants.d.ts +0 -26
- package/dist/lib/src/core/index.d.ts +0 -9
- package/dist/lib/src/core/parsers/array-name.parser.d.ts +0 -42
- package/dist/lib/src/core/parsers/array-string.parser.d.ts +0 -48
- package/dist/lib/src/core/parsers/index.d.ts +0 -11
- package/dist/lib/src/core/parsers/nama.parser.d.ts +0 -34
- package/dist/lib/src/core/parsers/parser.d.ts +0 -29
- package/dist/lib/src/core/parsers/string.parser.d.ts +0 -61
- package/dist/lib/src/core/utils/utils.d.ts +0 -14
- package/dist/lib/src/models/enums.d.ts +0 -91
- package/dist/lib/src/models/firstname.d.ts +0 -41
- package/dist/lib/src/models/index.d.ts +0 -12
- package/dist/lib/src/models/lastname.d.ts +0 -44
- package/dist/lib/src/models/misc.d.ts +0 -80
- package/dist/lib/src/models/name.d.ts +0 -48
- package/dist/lib/src/models/summary.d.ts +0 -23
- package/dist/lib/src/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/src/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/src/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/src/validators/common/validation-rule.d.ts +0 -69
- package/dist/lib/src/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/src/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/src/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/src/validators/index.d.ts +0 -21
- package/dist/lib/src/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/src/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/src/validators/nama.validator.d.ts +0 -21
- package/dist/lib/src/validators/namon.validator.d.ts +0 -20
- package/dist/lib/src/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/src/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/src/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/src/validators/validator.d.ts +0 -13
- package/dist/lib/usecases/compress.usecase.d.ts +0 -8
- package/dist/lib/usecases/constants.d.ts +0 -7
- package/dist/lib/usecases/describe.usecase.d.ts +0 -12
- package/dist/lib/usecases/format.usecase.d.ts +0 -6
- package/dist/lib/usecases/namefully.usecase.d.ts +0 -14
- package/dist/lib/usecases/shorten.usecase.d.ts +0 -6
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -82
- package/dist/lib/validators/array-name.validator.js.map +0 -1
- package/dist/lib/validators/array-string.validator.d.ts +0 -43
- package/dist/lib/validators/array-string.validator.js +0 -80
- package/dist/lib/validators/array-string.validator.js.map +0 -1
- package/dist/lib/validators/common/validation-error.d.ts +0 -19
- package/dist/lib/validators/common/validation-error.js +0 -26
- package/dist/lib/validators/common/validation-error.js.map +0 -1
- package/dist/lib/validators/common/validation-rule.d.ts +0 -69
- package/dist/lib/validators/common/validation-rule.js +0 -73
- package/dist/lib/validators/common/validation-rule.js.map +0 -1
- package/dist/lib/validators/common/validation-type.d.ts +0 -24
- package/dist/lib/validators/common/validation-type.js +0 -28
- package/dist/lib/validators/common/validation-type.js.map +0 -1
- package/dist/lib/validators/firstname.validator.d.ts +0 -20
- package/dist/lib/validators/firstname.validator.js +0 -29
- package/dist/lib/validators/firstname.validator.js.map +0 -1
- package/dist/lib/validators/fullname.validator.d.ts +0 -21
- package/dist/lib/validators/fullname.validator.js +0 -38
- package/dist/lib/validators/fullname.validator.js.map +0 -1
- package/dist/lib/validators/index.d.ts +0 -21
- package/dist/lib/validators/index.js +0 -35
- package/dist/lib/validators/index.js.map +0 -1
- package/dist/lib/validators/lastname.validator.d.ts +0 -20
- package/dist/lib/validators/lastname.validator.js +0 -29
- package/dist/lib/validators/lastname.validator.js.map +0 -1
- package/dist/lib/validators/middlename.validator.d.ts +0 -20
- package/dist/lib/validators/middlename.validator.js +0 -38
- package/dist/lib/validators/middlename.validator.js.map +0 -1
- package/dist/lib/validators/nama.validator.d.ts +0 -21
- package/dist/lib/validators/nama.validator.js +0 -43
- package/dist/lib/validators/nama.validator.js.map +0 -1
- package/dist/lib/validators/namon.validator.d.ts +0 -20
- package/dist/lib/validators/namon.validator.js +0 -29
- package/dist/lib/validators/namon.validator.js.map +0 -1
- package/dist/lib/validators/prefix.validator.d.ts +0 -14
- package/dist/lib/validators/prefix.validator.js +0 -31
- package/dist/lib/validators/prefix.validator.js.map +0 -1
- package/dist/lib/validators/string-name.validator.d.ts +0 -20
- package/dist/lib/validators/string-name.validator.js +0 -29
- package/dist/lib/validators/string-name.validator.js.map +0 -1
- package/dist/lib/validators/suffix.validator.d.ts +0 -14
- package/dist/lib/validators/suffix.validator.js +0 -31
- package/dist/lib/validators/suffix.validator.js.map +0 -1
- package/dist/lib/validators/validator.d.ts +0 -13
- package/dist/lib/validators/validator.js +0 -9
- package/dist/lib/validators/validator.js.map +0 -1
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Last name class definition
|
|
5
|
-
*
|
|
6
|
-
* Created on March 06, 2020
|
|
7
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
8
|
-
*/
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
/**
|
|
11
|
-
* Represents a last name with some extra functionalities
|
|
12
|
-
* @class
|
|
13
|
-
* @extends Name
|
|
14
|
-
*/
|
|
15
|
-
class Lastname extends index_1.Name {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a `Lastname`
|
|
18
|
-
* @param {string} father a piece of string that will be defined as a namon
|
|
19
|
-
* @param {string} [mother] additional pieces considered as a last name
|
|
20
|
-
* @param {LastnameFormat} [format] how to output a surname considering its
|
|
21
|
-
* subparts
|
|
22
|
-
*/
|
|
23
|
-
constructor(father, mother, format = 'father') {
|
|
24
|
-
super(father, index_1.Namon.LAST_NAME);
|
|
25
|
-
this.father = father;
|
|
26
|
-
this.mother = mother;
|
|
27
|
-
this.format = format;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
31
|
-
* dispersion and shape of the characters' distribution.
|
|
32
|
-
* @param {LastnameFormat} [format] overrides the how-to format of a surname
|
|
33
|
-
* output, considering its subparts.
|
|
34
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
35
|
-
*/
|
|
36
|
-
describe(format) {
|
|
37
|
-
format = format || this.format;
|
|
38
|
-
return new index_1.Summary(this.tostring(format));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Returns a string representation of the last name
|
|
42
|
-
* @param {LastnameFormat} [format] overrides the how-to format of a surname
|
|
43
|
-
* output, considering its subparts.
|
|
44
|
-
*/
|
|
45
|
-
tostring(format) {
|
|
46
|
-
format = format || this.format;
|
|
47
|
-
switch (format) {
|
|
48
|
-
case 'father':
|
|
49
|
-
return this.father;
|
|
50
|
-
case 'mother':
|
|
51
|
-
return this.mother || index_1.Separator.EMPTY;
|
|
52
|
-
case 'hyphenated':
|
|
53
|
-
return this.mother ? this.father.concat(index_1.Separator.HYPHEN, this.mother) : this.father;
|
|
54
|
-
case 'all':
|
|
55
|
-
return this.mother ? this.father.concat(index_1.Separator.SPACE, this.mother) : this.father;
|
|
56
|
-
// default:
|
|
57
|
-
// return this.father;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Gets the initials of the last name
|
|
62
|
-
* @returns {Array<string>} the initials
|
|
63
|
-
*/
|
|
64
|
-
getInitials(format) {
|
|
65
|
-
format = format || this.format;
|
|
66
|
-
const initials = [];
|
|
67
|
-
switch (format) {
|
|
68
|
-
case 'father':
|
|
69
|
-
initials.push(this.father[0]);
|
|
70
|
-
break;
|
|
71
|
-
case 'mother':
|
|
72
|
-
if (!!this.mother && this.mother.length)
|
|
73
|
-
initials.push(this.mother[0]);
|
|
74
|
-
break;
|
|
75
|
-
case 'hyphenated':
|
|
76
|
-
case 'all':
|
|
77
|
-
initials.push(this.father[0]);
|
|
78
|
-
if (!!this.mother && this.mother.length)
|
|
79
|
-
initials.push(this.mother[0]);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
return initials;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.Lastname = Lastname;
|
|
86
|
-
//# sourceMappingURL=lastname.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lastname.js","sourceRoot":"","sources":["../../../src/models/lastname.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,mCAA0E;AAE1E;;;;GAIG;AACH,MAAa,QAAS,SAAQ,YAAI;IAE9B;;;;;;OAMG;IACH,YAAmB,MAAc,EAAS,MAAe,EAAU,SAAyB,QAAQ;QAChG,KAAK,CAAC,MAAM,EAAE,aAAK,CAAC,SAAS,CAAC,CAAC;QADhB,WAAM,GAAN,MAAM,CAAQ;QAAS,WAAM,GAAN,MAAM,CAAS;QAAU,WAAM,GAAN,MAAM,CAA2B;IAEpG,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAuB;QAC5B,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QAC/B,OAAO,IAAI,eAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,MAAuB;QAC5B,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QAC/B,QAAO,MAAM,EAAE;YACX,KAAK,QAAQ;gBACT,OAAO,IAAI,CAAC,MAAM,CAAC;YACvB,KAAK,QAAQ;gBACT,OAAO,IAAI,CAAC,MAAM,IAAI,iBAAS,CAAC,KAAK,CAAC;YAC1C,KAAK,YAAY;gBACb,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;YACzF,KAAK,KAAK;gBACN,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;YACxF,WAAW;YACX,0BAA0B;SAC7B;IACL,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,MAAuB;QAC/B,MAAM,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QAC/B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,QAAO,MAAM,EAAE;YACX,KAAK,QAAQ;gBACT,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9B,MAAM;YACV,KAAK,QAAQ;gBACT,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;oBACnC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,MAAM;YACV,KAAK,YAAY,CAAC;YAAC,KAAK,KAAK;gBACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9B,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM;oBACnC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClC,MAAM;SACb;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAtED,4BAsEC"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Miscellaneous contents
|
|
3
|
-
*
|
|
4
|
-
* Created on March 07, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Parser } from '../core/index';
|
|
8
|
-
import { Name, Firstname, Lastname, Prefix, Suffix, Separator } from './index';
|
|
9
|
-
/**
|
|
10
|
-
* Interface for JSON signature that represents the full name
|
|
11
|
-
* @interface
|
|
12
|
-
*/
|
|
13
|
-
export interface Fullname {
|
|
14
|
-
firstname: Firstname;
|
|
15
|
-
lastname: Lastname;
|
|
16
|
-
middlename?: Name[];
|
|
17
|
-
prefix?: Prefix;
|
|
18
|
-
suffix?: Suffix;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Defines the two ways that a full name can be ordered: first or last name
|
|
22
|
-
* @typedef NameOrder
|
|
23
|
-
*/
|
|
24
|
-
export declare type NameOrder = 'firstname' | 'lastname';
|
|
25
|
-
/**
|
|
26
|
-
* Defines the distinct formats to output a surname
|
|
27
|
-
* @typedef LastnameFormat
|
|
28
|
-
*/
|
|
29
|
-
export declare type LastnameFormat = 'father' | 'mother' | 'hyphenated' | 'all';
|
|
30
|
-
/**
|
|
31
|
-
* Defines the ways the international community defines a title
|
|
32
|
-
*
|
|
33
|
-
* American and Canadian English follow slightly different rules for abbreviated
|
|
34
|
-
* titles than British and Australian English. In North American English, titles
|
|
35
|
-
* before a name require a period: `Mr., Mrs., Ms., Dr.` In British and Australian
|
|
36
|
-
* English, no full stops are used in these abbreviations.
|
|
37
|
-
* @typedef AbbrTitle
|
|
38
|
-
*/
|
|
39
|
-
export declare type AbbrTitle = 'us' | 'uk';
|
|
40
|
-
/**
|
|
41
|
-
* Interface for JSON signature that represents the configuration of the utility
|
|
42
|
-
* @interface
|
|
43
|
-
*/
|
|
44
|
-
export interface Config {
|
|
45
|
-
orderedBy: NameOrder;
|
|
46
|
-
separator: Separator;
|
|
47
|
-
titling: AbbrTitle;
|
|
48
|
-
ending: Separator;
|
|
49
|
-
bypass: boolean;
|
|
50
|
-
parser?: Parser<any>;
|
|
51
|
-
lastnameFormat?: LastnameFormat;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @interface Nama represents the JSON signature for the `NamaParser`
|
|
55
|
-
*/
|
|
56
|
-
export interface Nama {
|
|
57
|
-
prefix?: string;
|
|
58
|
-
firstname: string;
|
|
59
|
-
middlename?: string;
|
|
60
|
-
lastname: string;
|
|
61
|
-
suffix?: string;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* @interface Indexing represents the JSON signature for indexing name parts
|
|
65
|
-
*/
|
|
66
|
-
interface Indexing<T> {
|
|
67
|
-
prefix: T;
|
|
68
|
-
firstname: T;
|
|
69
|
-
middlename: T;
|
|
70
|
-
lastname: T;
|
|
71
|
-
suffix: T;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @interface NameIndex represents the JSON signature for indexing name parts
|
|
75
|
-
* using numbered index
|
|
76
|
-
* @extends Index<number>
|
|
77
|
-
*/
|
|
78
|
-
export interface NameIndex extends Indexing<number> {
|
|
79
|
-
}
|
|
80
|
-
export {};
|
package/dist/lib/models/misc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../../src/models/misc.ts"],"names":[],"mappings":""}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Name class definition
|
|
3
|
-
*
|
|
4
|
-
* Created on March 06, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Summary, Namon } from './index';
|
|
8
|
-
/**
|
|
9
|
-
* Represents a namon with some extra functionalities
|
|
10
|
-
* @class
|
|
11
|
-
* @see {@link Namon} interface to understand the concept of namon/nama.
|
|
12
|
-
*/
|
|
13
|
-
export declare class Name {
|
|
14
|
-
namon: string;
|
|
15
|
-
type: Namon;
|
|
16
|
-
private initial;
|
|
17
|
-
private body;
|
|
18
|
-
/**
|
|
19
|
-
* Constructs a `Name`
|
|
20
|
-
* @param namon a piece of string that will be defined as a namon
|
|
21
|
-
* @param type which namon that is
|
|
22
|
-
*/
|
|
23
|
-
constructor(namon: string, type: Namon, capitalized?: 'initial' | 'all');
|
|
24
|
-
/**
|
|
25
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
26
|
-
* dispersion and shape of the characters' distribution.
|
|
27
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
28
|
-
*/
|
|
29
|
-
describe(): Summary;
|
|
30
|
-
/**
|
|
31
|
-
* Gets the initials of the name
|
|
32
|
-
* @returns {Array<string>} the initials
|
|
33
|
-
*/
|
|
34
|
-
getInitials(): string[];
|
|
35
|
-
/**
|
|
36
|
-
* Capitalizes a name
|
|
37
|
-
* @param {'initial' | 'all'} option how to capitalize it
|
|
38
|
-
*/
|
|
39
|
-
protected capitalize(option?: 'initial' | 'all'): void;
|
|
40
|
-
/**
|
|
41
|
-
* Converts all the alphabetic characters in a string to lowercase
|
|
42
|
-
*/
|
|
43
|
-
lower(): string;
|
|
44
|
-
/**
|
|
45
|
-
* Converts all the alphabetic characters in a string to uppercase
|
|
46
|
-
*/
|
|
47
|
-
upper(): string;
|
|
48
|
-
}
|
package/dist/lib/models/name.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Name class definition
|
|
5
|
-
*
|
|
6
|
-
* Created on March 06, 2020
|
|
7
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
8
|
-
*/
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
/**
|
|
11
|
-
* Represents a namon with some extra functionalities
|
|
12
|
-
* @class
|
|
13
|
-
* @see {@link Namon} interface to understand the concept of namon/nama.
|
|
14
|
-
*/
|
|
15
|
-
class Name {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a `Name`
|
|
18
|
-
* @param namon a piece of string that will be defined as a namon
|
|
19
|
-
* @param type which namon that is
|
|
20
|
-
*/
|
|
21
|
-
constructor(namon, type, capitalized) {
|
|
22
|
-
this.namon = namon;
|
|
23
|
-
this.type = type;
|
|
24
|
-
this.initial = namon[0];
|
|
25
|
-
this.body = namon.slice(1, namon.length);
|
|
26
|
-
if (!!capitalized)
|
|
27
|
-
this.capitalize(capitalized);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
31
|
-
* dispersion and shape of the characters' distribution.
|
|
32
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
33
|
-
*/
|
|
34
|
-
describe() {
|
|
35
|
-
return new index_1.Summary(this.namon);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Gets the initials of the name
|
|
39
|
-
* @returns {Array<string>} the initials
|
|
40
|
-
*/
|
|
41
|
-
getInitials() {
|
|
42
|
-
return [this.initial];
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Capitalizes a name
|
|
46
|
-
* @param {'initial' | 'all'} option how to capitalize it
|
|
47
|
-
*/
|
|
48
|
-
capitalize(option = 'initial') {
|
|
49
|
-
if (option === 'initial') {
|
|
50
|
-
this.initial = this.initial.toUpperCase();
|
|
51
|
-
this.namon = this.initial.concat(this.body);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.initial = this.initial.toUpperCase();
|
|
55
|
-
this.namon = this.namon.toUpperCase();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Converts all the alphabetic characters in a string to lowercase
|
|
60
|
-
*/
|
|
61
|
-
lower() {
|
|
62
|
-
return this.namon.toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Converts all the alphabetic characters in a string to uppercase
|
|
66
|
-
*/
|
|
67
|
-
upper() {
|
|
68
|
-
return this.namon.toUpperCase();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.Name = Name;
|
|
72
|
-
//# sourceMappingURL=name.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"name.js","sourceRoot":"","sources":["../../../src/models/name.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,mCAAyC;AAEzC;;;;GAIG;AACH,MAAa,IAAI;IAKb;;;;OAIG;IACH,YAAmB,KAAa,EAAS,IAAW,EAAE,WAA+B;QAAlE,UAAK,GAAL,KAAK,CAAQ;QAAS,SAAI,GAAJ,IAAI,CAAO;QAChD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,CAAC,WAAW;YAAE,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACJ,OAAO,IAAI,eAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,WAAW;QACP,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACO,UAAU,CAAC,SAA4B,SAAS;QACtD,IAAI,MAAM,KAAK,SAAS,EAAE;YACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC/C;aAAM;YACH,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACzC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;CACJ;AA5DD,oBA4DC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the statistical summary of a string representation
|
|
3
|
-
* @class
|
|
4
|
-
*/
|
|
5
|
-
export declare class Summary {
|
|
6
|
-
private namon;
|
|
7
|
-
count: number;
|
|
8
|
-
frequency: number;
|
|
9
|
-
top: string;
|
|
10
|
-
unique: number;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a `Summary` of a given string of alphabetical characters
|
|
13
|
-
* @param namon piece of name
|
|
14
|
-
* @param restrictions a set of undesired characters
|
|
15
|
-
*/
|
|
16
|
-
constructor(namon: string, restrictions?: string[]);
|
|
17
|
-
/**
|
|
18
|
-
* Returns a string representation of the summary
|
|
19
|
-
*/
|
|
20
|
-
tostring(): string;
|
|
21
|
-
private compute;
|
|
22
|
-
private groupByChar;
|
|
23
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Summary of descriptive stats of the name
|
|
5
|
-
*
|
|
6
|
-
* Created on March 06, 2020
|
|
7
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
8
|
-
*/
|
|
9
|
-
const index_1 = require("./index");
|
|
10
|
-
/**
|
|
11
|
-
* Represents the statistical summary of a string representation
|
|
12
|
-
* @class
|
|
13
|
-
*/
|
|
14
|
-
class Summary {
|
|
15
|
-
/**
|
|
16
|
-
* Creates a `Summary` of a given string of alphabetical characters
|
|
17
|
-
* @param namon piece of name
|
|
18
|
-
* @param restrictions a set of undesired characters
|
|
19
|
-
*/
|
|
20
|
-
constructor(namon, restrictions = [index_1.Separator.SPACE]) {
|
|
21
|
-
this.namon = namon;
|
|
22
|
-
this.compute(restrictions);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Returns a string representation of the summary
|
|
26
|
-
*/
|
|
27
|
-
tostring() {
|
|
28
|
-
return index_1.Separator.EMPTY.concat(`Descriptive statistics for "${this.namon}" \n`, `count : ${this.count} \n`, `frequency: ${this.frequency} \n`, `top : ${this.top} \n`, `unique : ${this.unique} \n`);
|
|
29
|
-
}
|
|
30
|
-
compute(restrictions = []) {
|
|
31
|
-
// compute stats for the string
|
|
32
|
-
let count = 0, maxfreq = 0, uniq = 0, top = '';
|
|
33
|
-
const freqs = this.groupByChar();
|
|
34
|
-
for (const char in freqs) {
|
|
35
|
-
if (restrictions.indexOf(char) === -1) {
|
|
36
|
-
count += freqs[char];
|
|
37
|
-
if (freqs[char] >= maxfreq) {
|
|
38
|
-
maxfreq = freqs[char];
|
|
39
|
-
top = char;
|
|
40
|
-
}
|
|
41
|
-
uniq++;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
this.count = count;
|
|
45
|
-
this.frequency = maxfreq;
|
|
46
|
-
this.top = top;
|
|
47
|
-
this.unique = uniq;
|
|
48
|
-
}
|
|
49
|
-
groupByChar() {
|
|
50
|
-
const frequencies = {};
|
|
51
|
-
for (const char of this.namon.toUpperCase())
|
|
52
|
-
if (Object.keys(frequencies).includes(char))
|
|
53
|
-
frequencies[char] += 1;
|
|
54
|
-
else
|
|
55
|
-
frequencies[char] = 1;
|
|
56
|
-
return frequencies;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.Summary = Summary;
|
|
60
|
-
//# sourceMappingURL=summary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"summary.js","sourceRoot":"","sources":["../../../src/models/summary.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,mCAAoC;AAEpC;;;GAGG;AACH,MAAa,OAAO;IAMhB;;;;OAIG;IACH,YAAoB,KAAa,EAAE,eAAyB,CAAC,iBAAS,CAAC,KAAK,CAAC;QAAzD,UAAK,GAAL,KAAK,CAAQ;QAC7B,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,QAAQ;QACJ,OAAO,iBAAS,CAAC,KAAK,CAAC,MAAM,CACzB,+BAA+B,IAAI,CAAC,KAAK,MAAM,EAC/C,cAAc,IAAI,CAAC,KAAK,KAAK,EAC7B,cAAc,IAAI,CAAC,SAAS,KAAK,EACjC,cAAc,IAAI,CAAC,GAAG,KAAK,EAC3B,cAAc,IAAI,CAAC,MAAM,KAAK,CACjC,CAAC;IACN,CAAC;IAEO,OAAO,CAAC,eAAyB,EAAE;QACvC,+BAA+B;QAC/B,IAAI,KAAK,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACtB,IAAI,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;gBACnC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;gBACrB,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,EAAE;oBACxB,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;oBACtB,GAAG,GAAG,IAAI,CAAC;iBACd;gBACD,IAAI,EAAE,CAAC;aACV;SACJ;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAEO,WAAW;QACf,MAAM,WAAW,GAA8B,EAAE,CAAC;QAClD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;YACvC,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACvC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;gBAEvB,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ;AA3DD,0BA2DC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants
|
|
3
|
-
*
|
|
4
|
-
* Created on March 07, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Config, NameIndex } from '../models/index';
|
|
8
|
-
/**
|
|
9
|
-
* The current version of `Namefully`.
|
|
10
|
-
* @constant
|
|
11
|
-
*/
|
|
12
|
-
export declare const version = "1.0.9";
|
|
13
|
-
/**
|
|
14
|
-
* CONFIG constant
|
|
15
|
-
* @constant
|
|
16
|
-
* @type {Config}
|
|
17
|
-
* @default
|
|
18
|
-
*/
|
|
19
|
-
export declare const CONFIG: Config;
|
|
20
|
-
/**
|
|
21
|
-
* NAME_INDEX constant
|
|
22
|
-
* @constant
|
|
23
|
-
* @type {NameIndex}
|
|
24
|
-
* @default
|
|
25
|
-
*/
|
|
26
|
-
export declare const NAME_INDEX: NameIndex;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An array `Name` parser
|
|
3
|
-
*
|
|
4
|
-
* Created on March 15, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Name, Fullname, LastnameFormat } from '../../models/index';
|
|
8
|
-
import { Parser } from './parser';
|
|
9
|
-
/**
|
|
10
|
-
* Represents a `Name[]` parser
|
|
11
|
-
* @class
|
|
12
|
-
* @implements {Parser<Name[]>}
|
|
13
|
-
* @classdesc
|
|
14
|
-
* This parser parses an array of the class `Name` while checking that every part
|
|
15
|
-
* plays the role they are supposed to play. The class `Name` is a ready-made
|
|
16
|
-
* recipe that saves the how-to parsing for a raw data input.
|
|
17
|
-
*
|
|
18
|
-
* **NOTE**:
|
|
19
|
-
* In this specific case, the user is expected to carefully set each name part
|
|
20
|
-
* and submit a high-quality data. Why is this parser if the data is already
|
|
21
|
-
* shaped as wanted? Well, it is better to be safe than sorry, so we implement a
|
|
22
|
-
* double-check of these values and reconfirm a cleaner data. Remember, namefully
|
|
23
|
-
* works like a trapdoor, once the data is set and confirmed safe, no editing is
|
|
24
|
-
* possible.
|
|
25
|
-
*/
|
|
26
|
-
export default class ArrayNameParser implements Parser<Name[]> {
|
|
27
|
-
raw: Name[];
|
|
28
|
-
/**
|
|
29
|
-
* Create a parser ready to parse the raw data
|
|
30
|
-
* @param {Name[]} raw data
|
|
31
|
-
*/
|
|
32
|
-
constructor(raw: Name[]);
|
|
33
|
-
/**
|
|
34
|
-
* Parses the raw data into a full name
|
|
35
|
-
* @returns {Fullname}
|
|
36
|
-
*/
|
|
37
|
-
parse(options: {
|
|
38
|
-
bypass: boolean;
|
|
39
|
-
lastnameFormat: LastnameFormat;
|
|
40
|
-
}): Fullname;
|
|
41
|
-
private distribute;
|
|
42
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An array of string parser
|
|
3
|
-
*
|
|
4
|
-
* Created on March 15, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Fullname, NameOrder } from '../../models/index';
|
|
8
|
-
import { Parser } from './parser';
|
|
9
|
-
/**
|
|
10
|
-
* Represents an array string parser
|
|
11
|
-
* @class
|
|
12
|
-
* @implements {Parser<string[]>}
|
|
13
|
-
* @classdesc
|
|
14
|
-
* This parser parses an array of string name following a specific order based
|
|
15
|
-
* on the count of elements. It is expected that the array has to be between two
|
|
16
|
-
* and five elements. Also, the order of appearance set in the configuration
|
|
17
|
-
* influences how this parsing is carried out.
|
|
18
|
-
*
|
|
19
|
-
* Ordered by first name, the parser works as follows:
|
|
20
|
-
* - 2 elements: firstname lastname
|
|
21
|
-
* - 3 elements: firstname middlename lastname
|
|
22
|
-
* - 4 elements: prefix firstname middlename lastname
|
|
23
|
-
* - 5 elements: prefix firstname middlename lastname suffix
|
|
24
|
-
*
|
|
25
|
-
* Ordered by last name, the parser works as follows:
|
|
26
|
-
* - 2 elements: lastname firstname
|
|
27
|
-
* - 3 elements: lastname firstname middlename
|
|
28
|
-
* - 4 elements: prefix lastname firstname middlename
|
|
29
|
-
* - 5 elements: prefix lastname firstname middlename suffix
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
export default class ArrayStringParser implements Parser<string[]> {
|
|
33
|
-
raw: string[];
|
|
34
|
-
/**
|
|
35
|
-
* Create a parser ready to parse the raw data
|
|
36
|
-
* @param {Array<string>} raw data
|
|
37
|
-
*/
|
|
38
|
-
constructor(raw: string[]);
|
|
39
|
-
/**
|
|
40
|
-
* Parses the raw data into a full name
|
|
41
|
-
* @returns {Fullname}
|
|
42
|
-
*/
|
|
43
|
-
parse(options: {
|
|
44
|
-
orderedBy: NameOrder;
|
|
45
|
-
bypass: boolean;
|
|
46
|
-
}): Fullname;
|
|
47
|
-
private distribute;
|
|
48
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Export the local parsers
|
|
3
|
-
*
|
|
4
|
-
* Created on March 03, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
export * from './parser';
|
|
8
|
-
export { default as ArrayNameParser } from './array-name.parser';
|
|
9
|
-
export { default as ArrayStringParser } from './array-string.parser';
|
|
10
|
-
export { default as NamaParser } from './nama.parser';
|
|
11
|
-
export { default as StringParser } from './string.parser';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A `Nama` (JSON signature) parser
|
|
3
|
-
*
|
|
4
|
-
* Created on March 15, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Nama, Fullname } from '../../models/index';
|
|
8
|
-
import { Parser } from './parser';
|
|
9
|
-
/**
|
|
10
|
-
* Represents a `Nama` parser
|
|
11
|
-
* @class
|
|
12
|
-
* @implements {Parser<Nama>}
|
|
13
|
-
* @classdesc
|
|
14
|
-
* This parser parses a JSON signature of the name parts provided as string
|
|
15
|
-
* values. This is to facilitate a developer's life that holds users' info in a
|
|
16
|
-
* JSON format. In other words, the developer only needs to provide similar info
|
|
17
|
-
* and the rest will follow.
|
|
18
|
-
*/
|
|
19
|
-
export default class NamaParser implements Parser<Nama> {
|
|
20
|
-
raw: Nama;
|
|
21
|
-
/**
|
|
22
|
-
* Create a parser ready to parse the raw data
|
|
23
|
-
* @param {Nama} raw data as JSON object
|
|
24
|
-
*/
|
|
25
|
-
constructor(raw: Nama);
|
|
26
|
-
/**
|
|
27
|
-
* Parses the raw data into a full name
|
|
28
|
-
* @returns {Fullname}
|
|
29
|
-
*/
|
|
30
|
-
parse(options: {
|
|
31
|
-
bypass: boolean;
|
|
32
|
-
}): Fullname;
|
|
33
|
-
private distribute;
|
|
34
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A `Parser` contract
|
|
3
|
-
*
|
|
4
|
-
* Created on March 15, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Fullname, Separator, NameOrder, LastnameFormat } from '../../models/index';
|
|
8
|
-
/**
|
|
9
|
-
* Interface for JSON signature that represents a generic parser
|
|
10
|
-
* @interface
|
|
11
|
-
*/
|
|
12
|
-
export interface Parser<T> {
|
|
13
|
-
/**
|
|
14
|
-
* raw data to be parsed
|
|
15
|
-
* @type {T}
|
|
16
|
-
*/
|
|
17
|
-
raw: T;
|
|
18
|
-
/**
|
|
19
|
-
* Parses the raw data into a full name
|
|
20
|
-
* @param {Config} [options]
|
|
21
|
-
* @returns {Fullname}
|
|
22
|
-
*/
|
|
23
|
-
parse(options?: Partial<{
|
|
24
|
-
orderedBy: NameOrder;
|
|
25
|
-
separator: Separator;
|
|
26
|
-
bypass: boolean;
|
|
27
|
-
lastnameFormat: LastnameFormat;
|
|
28
|
-
}>): Fullname;
|
|
29
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A string parser
|
|
3
|
-
*
|
|
4
|
-
* Created on March 15, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Separator, Fullname, NameOrder } from '../../models/index';
|
|
8
|
-
import { Parser } from './index';
|
|
9
|
-
/**
|
|
10
|
-
* Represents a string parser
|
|
11
|
-
* @class
|
|
12
|
-
* @implements {Parser}
|
|
13
|
-
* @classdesc
|
|
14
|
-
* This parser parses a string name using a separator, if set, or simply using
|
|
15
|
-
* the space character <' '> as a basis for the split.
|
|
16
|
-
*
|
|
17
|
-
* **NOTE**:
|
|
18
|
-
* A string name is basically a string type containing the name parts differentiated
|
|
19
|
-
* with the help of a separator. The default separator is the character <space>
|
|
20
|
-
* or <' '>. However, it can be very, very helpful to use a distinct separator
|
|
21
|
-
* (e.g., a colon <:>) to handle multiple names for a `Namon`. That is to say,
|
|
22
|
-
* a piece of name shaped as `De La Cruz` is a last name that needs to be handled
|
|
23
|
-
* as a whole, and therefore requires that a different type of separator to split
|
|
24
|
-
* up the name parts. Alternatively, the `ArrayStringParser` can be used by indicating
|
|
25
|
-
* specifically which part of the name is what. Do note that this parser is actually
|
|
26
|
-
* a wrapper of the `ArrayStringParser`.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* Given the name `Maria De La Cruz`, using this parser without indicating a
|
|
30
|
-
* separator different than <space> will definitely throw an error. So, if the proper
|
|
31
|
-
* proper of doing when `De La Cruz` is the last name:
|
|
32
|
-
* ```
|
|
33
|
-
* > const name = new Namefully('Maria:De La Cruz', { separator: Separator.COLON })
|
|
34
|
-
* > console.log(name.getLastname())
|
|
35
|
-
* De La Cruz
|
|
36
|
-
* ```
|
|
37
|
-
* Or
|
|
38
|
-
* ```
|
|
39
|
-
* > const name = new Namefully(['Maria', 'De La Cruz'])
|
|
40
|
-
* > console.log(name.getLastname())
|
|
41
|
-
* De La Cruz
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export default class StringParser implements Parser<string> {
|
|
45
|
-
raw: string;
|
|
46
|
-
/**
|
|
47
|
-
* Create a parser ready to parse the raw data
|
|
48
|
-
* @param {string} raw data as a string representation
|
|
49
|
-
*/
|
|
50
|
-
constructor(raw: string);
|
|
51
|
-
/**
|
|
52
|
-
* Parses the raw data into a full name
|
|
53
|
-
* @param options how to parse
|
|
54
|
-
* @returns {Fullname}
|
|
55
|
-
*/
|
|
56
|
-
parse(options: {
|
|
57
|
-
orderedBy: NameOrder;
|
|
58
|
-
separator: Separator;
|
|
59
|
-
bypass: boolean;
|
|
60
|
-
}): Fullname;
|
|
61
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utils for the core functionalities of `Namefully`
|
|
3
|
-
*
|
|
4
|
-
* Created on March 16, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { NameIndex, NameOrder } from '../../models';
|
|
8
|
-
/**
|
|
9
|
-
* Reorganizes the existing global indexes for array of name parts
|
|
10
|
-
* @param orderedBy by first or last name
|
|
11
|
-
* @param argLength length of the provided array
|
|
12
|
-
* @param nameIndex global preset of indexing
|
|
13
|
-
*/
|
|
14
|
-
export declare function organizeNameIndex(orderedBy: NameOrder, argLength: number, nameIndex?: NameIndex): NameIndex;
|