namefully 1.1.0 → 1.2.1
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/dist/lib/config.js +112 -0
- package/dist/lib/constants.js +30 -0
- package/dist/lib/error.js +92 -0
- package/dist/lib/full-name.js +115 -0
- package/dist/lib/index.js +27 -12
- package/dist/lib/name.js +230 -0
- package/dist/lib/namefully.js +368 -681
- package/dist/lib/parser.js +138 -0
- package/dist/lib/types.js +107 -0
- package/dist/lib/utils.js +92 -0
- package/dist/lib/validator.js +301 -0
- package/dist/types/config.d.ts +97 -0
- package/dist/types/constants.d.ts +4 -0
- package/dist/types/error.d.ts +158 -0
- package/dist/types/full-name.d.ts +54 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/name.d.ts +126 -0
- package/dist/types/namefully.d.ts +313 -0
- package/dist/types/parser.d.ts +41 -0
- package/dist/types/types.d.ts +127 -0
- package/dist/types/utils.d.ts +53 -0
- package/dist/types/validator.d.ts +57 -0
- package/dist/umd/namefully.js +1503 -2900
- package/dist/umd/namefully.min.js +1 -3
- package/package.json +28 -38
- package/readme.md +138 -167
- package/changelog.md +0 -134
- package/dist/lib/core/constants.d.ts +0 -48
- package/dist/lib/core/constants.js +0 -101
- package/dist/lib/core/constants.js.map +0 -1
- package/dist/lib/core/core.d.ts +0 -17
- package/dist/lib/core/core.js +0 -24
- package/dist/lib/core/core.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 -41
- package/dist/lib/core/parsers/array-name.parser.js +0 -86
- package/dist/lib/core/parsers/array-name.parser.js.map +0 -1
- package/dist/lib/core/parsers/array-string.parser.d.ts +0 -47
- package/dist/lib/core/parsers/array-string.parser.js +0 -95
- 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 -33
- package/dist/lib/core/parsers/nama.parser.js +0 -74
- package/dist/lib/core/parsers/nama.parser.js.map +0 -1
- package/dist/lib/core/parsers/parser.d.ts +0 -28
- 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 -60
- package/dist/lib/core/parsers/string.parser.js +0 -62
- package/dist/lib/core/parsers/string.parser.js.map +0 -1
- package/dist/lib/core/utils.d.ts +0 -52
- package/dist/lib/core/utils.js +0 -178
- package/dist/lib/core/utils.js.map +0 -1
- package/dist/lib/index.d.ts +0 -10
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/models/enums.d.ts +0 -106
- package/dist/lib/models/enums.js +0 -114
- package/dist/lib/models/enums.js.map +0 -1
- package/dist/lib/models/firstname.d.ts +0 -77
- package/dist/lib/models/firstname.js +0 -131
- package/dist/lib/models/firstname.js.map +0 -1
- package/dist/lib/models/fullname.d.ts +0 -73
- package/dist/lib/models/fullname.js +0 -99
- package/dist/lib/models/fullname.js.map +0 -1
- package/dist/lib/models/index.d.ts +0 -13
- package/dist/lib/models/index.js +0 -16
- package/dist/lib/models/index.js.map +0 -1
- package/dist/lib/models/lastname.d.ts +0 -80
- package/dist/lib/models/lastname.js +0 -157
- package/dist/lib/models/lastname.js.map +0 -1
- package/dist/lib/models/misc.d.ts +0 -108
- 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 -76
- package/dist/lib/models/name.js +0 -115
- package/dist/lib/models/name.js.map +0 -1
- package/dist/lib/models/summary.d.ts +0 -26
- package/dist/lib/models/summary.js +0 -61
- package/dist/lib/models/summary.js.map +0 -1
- package/dist/lib/namefully.d.ts +0 -302
- package/dist/lib/namefully.js.map +0 -1
- package/dist/lib/validators/array-name.validator.d.ts +0 -25
- package/dist/lib/validators/array-name.validator.js +0 -75
- 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 -76
- 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 -72
- package/dist/lib/validators/common/validation-rule.js +0 -76
- 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 -44
- 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
- package/dist/umd/namefully.js.map +0 -1
- package/dist/umd/namefully.min.js.LICENSE.txt +0 -29
- package/dist/umd/namefully.min.js.map +0 -1
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Miscellaneous types
|
|
3
|
-
*
|
|
4
|
-
* Created on March 07, 2020
|
|
5
|
-
* @author Ralph Florent <ralflornt@gmail.com>
|
|
6
|
-
*/
|
|
7
|
-
import { Parser } from '../core/parsers';
|
|
8
|
-
import { Separator } from './enums';
|
|
9
|
-
/**
|
|
10
|
-
* Defines the two ways that a full name can be ordered: first or last name
|
|
11
|
-
* @typedef NameOrder
|
|
12
|
-
*/
|
|
13
|
-
export declare type NameOrder = 'firstname' | 'fn' | 'lastname' | 'ln';
|
|
14
|
-
/**
|
|
15
|
-
* Defines the three parts that a birth name
|
|
16
|
-
* @typedef NameType
|
|
17
|
-
*/
|
|
18
|
-
export declare type NameType = 'firstname' | 'fn' | 'lastname' | 'ln' | 'middlename' | 'mn';
|
|
19
|
-
/**
|
|
20
|
-
* Defines the distinct formats to output a surname
|
|
21
|
-
* @typedef LastnameFormat
|
|
22
|
-
*/
|
|
23
|
-
export declare type LastnameFormat = 'father' | 'mother' | 'hyphenated' | 'all';
|
|
24
|
-
/**
|
|
25
|
-
* Defines the ways the international community defines a title
|
|
26
|
-
*
|
|
27
|
-
* American and Canadian English follow slightly different rules for abbreviated
|
|
28
|
-
* titles than British and Australian English. In North American English, titles
|
|
29
|
-
* before a name require a period: `Mr., Mrs., Ms., Dr.` In British and Australian
|
|
30
|
-
* English, no full stops are used in these abbreviations.
|
|
31
|
-
* @typedef AbbrTitle
|
|
32
|
-
*/
|
|
33
|
-
export declare type AbbrTitle = 'us' | 'uk';
|
|
34
|
-
/**
|
|
35
|
-
* Interface for JSON signature that represents the configuration of the utility
|
|
36
|
-
* @interface
|
|
37
|
-
*/
|
|
38
|
-
export interface Config {
|
|
39
|
-
/**
|
|
40
|
-
* The order of appearance of a full name: by first name or last name
|
|
41
|
-
*/
|
|
42
|
-
orderedBy: NameOrder;
|
|
43
|
-
/**
|
|
44
|
-
* For literal string input, this is the parameter used to indicate the token
|
|
45
|
-
* to utilize to split the string names.
|
|
46
|
-
*/
|
|
47
|
-
separator: Separator;
|
|
48
|
-
/**
|
|
49
|
-
* Whether or not to add period to a prefix using the American or British way.
|
|
50
|
-
*/
|
|
51
|
-
titling: AbbrTitle;
|
|
52
|
-
/**
|
|
53
|
-
* Indicates if the ending suffix should be separated with a comma or space.
|
|
54
|
-
*/
|
|
55
|
-
ending: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Bypass the validation rules with this option. Since we only provide a
|
|
58
|
-
* handful of suffixes or prefixes in English, this paramter is ideal to
|
|
59
|
-
* avoid checking the validity of them.
|
|
60
|
-
*/
|
|
61
|
-
bypass: boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Custom parser, a user-defined parser indicating how to the name set is
|
|
64
|
-
* organized. Namefully cannot guess it.
|
|
65
|
-
*/
|
|
66
|
-
parser?: Parser<any>;
|
|
67
|
-
/**
|
|
68
|
-
* how to format a surname:
|
|
69
|
-
* - 'father' (father name only)
|
|
70
|
-
* - 'mother' (mother name only)
|
|
71
|
-
* - 'hyphenated' (joining both father and mother names with a hyphen)
|
|
72
|
-
* - 'all' (joining both father and mother names with a space).
|
|
73
|
-
*
|
|
74
|
-
* This parameter can be set either by an instance of a last name or during
|
|
75
|
-
* the creation of a namefully instance. To avoid ambiguity, we prioritize as
|
|
76
|
-
* source of truth the value set as optional parameter when instantiating
|
|
77
|
-
* namefully.
|
|
78
|
-
*/
|
|
79
|
-
lastnameFormat?: LastnameFormat;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* @interface Nama represents the JSON signature for the `NamaParser`
|
|
83
|
-
*/
|
|
84
|
-
export interface Nama {
|
|
85
|
-
prefix?: string;
|
|
86
|
-
firstname: string;
|
|
87
|
-
middlename?: string;
|
|
88
|
-
lastname: string;
|
|
89
|
-
suffix?: string;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @interface Indexing represents the JSON signature for indexing name parts
|
|
93
|
-
*/
|
|
94
|
-
interface Indexing<T> {
|
|
95
|
-
prefix: T;
|
|
96
|
-
firstname: T;
|
|
97
|
-
middlename: T;
|
|
98
|
-
lastname: T;
|
|
99
|
-
suffix: T;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* @interface NameIndex represents the JSON signature for indexing name parts
|
|
103
|
-
* using numbered index
|
|
104
|
-
* @extends Index<number>
|
|
105
|
-
*/
|
|
106
|
-
export interface NameIndex extends Indexing<number> {
|
|
107
|
-
}
|
|
108
|
-
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,76 +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 readonly initial;
|
|
17
|
-
private readonly 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
|
-
* @param cap which kind of capitalizations
|
|
23
|
-
*/
|
|
24
|
-
constructor(namon: string, type: Namon, cap?: 'initial' | 'all');
|
|
25
|
-
/**
|
|
26
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
27
|
-
* dispersion and shape of the characters' distribution.
|
|
28
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
29
|
-
*/
|
|
30
|
-
describe(): Summary;
|
|
31
|
-
/**
|
|
32
|
-
* Returns a string representation of the namon
|
|
33
|
-
*/
|
|
34
|
-
tostring(): string;
|
|
35
|
-
/**
|
|
36
|
-
* Gets the initials of the name
|
|
37
|
-
*/
|
|
38
|
-
getInitials(): string[];
|
|
39
|
-
/**
|
|
40
|
-
* Capitalizes a name
|
|
41
|
-
* @param {'initial' | 'all'} option how to capitalize it
|
|
42
|
-
*/
|
|
43
|
-
capitalize(option?: 'initial' | 'all'): Name;
|
|
44
|
-
/**
|
|
45
|
-
* De-capitalizes a name
|
|
46
|
-
* @param {'initial' | 'all'} option how to decapitalize it
|
|
47
|
-
*/
|
|
48
|
-
decapitalize(option?: 'initial' | 'all'): Name;
|
|
49
|
-
/**
|
|
50
|
-
* Normalizes the name as it should be
|
|
51
|
-
*/
|
|
52
|
-
normalize(): Name;
|
|
53
|
-
/**
|
|
54
|
-
* Resets to the initial namon
|
|
55
|
-
*/
|
|
56
|
-
reset(): Name;
|
|
57
|
-
/**
|
|
58
|
-
* Returns an ascii representation of each characters of a name
|
|
59
|
-
* @param restrictions chars to skip
|
|
60
|
-
*/
|
|
61
|
-
ascii(restrictions?: string[]): number[];
|
|
62
|
-
/**
|
|
63
|
-
* Returns a password-like representation of a name
|
|
64
|
-
*/
|
|
65
|
-
passwd(): string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Aliases for `Name`
|
|
69
|
-
*/
|
|
70
|
-
export interface Name {
|
|
71
|
-
cap: typeof Name.prototype.capitalize;
|
|
72
|
-
decap: typeof Name.prototype.decapitalize;
|
|
73
|
-
norm: typeof Name.prototype.normalize;
|
|
74
|
-
stats: typeof Name.prototype.describe;
|
|
75
|
-
inits: typeof Name.prototype.getInitials;
|
|
76
|
-
}
|
package/dist/lib/models/name.js
DELETED
|
@@ -1,115 +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
|
-
const core_1 = require("../core");
|
|
11
|
-
/**
|
|
12
|
-
* Represents a namon with some extra functionalities
|
|
13
|
-
* @class
|
|
14
|
-
* @see {@link Namon} interface to understand the concept of namon/nama.
|
|
15
|
-
*/
|
|
16
|
-
class Name {
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a `Name`
|
|
19
|
-
* @param namon a piece of string that will be defined as a namon
|
|
20
|
-
* @param type which namon that is
|
|
21
|
-
* @param cap which kind of capitalizations
|
|
22
|
-
*/
|
|
23
|
-
constructor(namon, type, cap) {
|
|
24
|
-
this.namon = namon;
|
|
25
|
-
this.type = type;
|
|
26
|
-
this.initial = namon[0];
|
|
27
|
-
this.body = namon.slice(1);
|
|
28
|
-
if (!!cap)
|
|
29
|
-
this.capitalize(cap);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Gives some descriptive statistics that summarize the central tendency,
|
|
33
|
-
* dispersion and shape of the characters' distribution.
|
|
34
|
-
* @see {@link describe} in `Namefully` class for further information
|
|
35
|
-
*/
|
|
36
|
-
describe() {
|
|
37
|
-
return new index_1.Summary(this.namon);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns a string representation of the namon
|
|
41
|
-
*/
|
|
42
|
-
tostring() {
|
|
43
|
-
return this.namon;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Gets the initials of the name
|
|
47
|
-
*/
|
|
48
|
-
getInitials() {
|
|
49
|
-
return [this.namon[0]];
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Capitalizes a name
|
|
53
|
-
* @param {'initial' | 'all'} option how to capitalize it
|
|
54
|
-
*/
|
|
55
|
-
capitalize(option = 'initial') {
|
|
56
|
-
const initial = this.initial.toUpperCase();
|
|
57
|
-
if (option === 'initial') {
|
|
58
|
-
this.namon = initial.concat(this.body);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.namon = this.namon.toUpperCase();
|
|
62
|
-
}
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* De-capitalizes a name
|
|
67
|
-
* @param {'initial' | 'all'} option how to decapitalize it
|
|
68
|
-
*/
|
|
69
|
-
decapitalize(option = 'initial') {
|
|
70
|
-
const initial = this.initial.toLowerCase();
|
|
71
|
-
if (option === 'initial') {
|
|
72
|
-
this.namon = initial.concat(this.body);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
this.namon = initial.concat(this.body.toLowerCase());
|
|
76
|
-
}
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Normalizes the name as it should be
|
|
81
|
-
*/
|
|
82
|
-
normalize() {
|
|
83
|
-
this.namon = this.namon[0]
|
|
84
|
-
.toUpperCase()
|
|
85
|
-
.concat(this.namon.slice(1).toLowerCase());
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Resets to the initial namon
|
|
90
|
-
*/
|
|
91
|
-
reset() {
|
|
92
|
-
this.namon = this.initial.concat(this.body);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Returns an ascii representation of each characters of a name
|
|
97
|
-
* @param restrictions chars to skip
|
|
98
|
-
*/
|
|
99
|
-
ascii(restrictions) {
|
|
100
|
-
return core_1.convertToAscii(this.namon, restrictions);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns a password-like representation of a name
|
|
104
|
-
*/
|
|
105
|
-
passwd() {
|
|
106
|
-
return core_1.generatePassword(this.namon);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.Name = Name;
|
|
110
|
-
Name.prototype.cap = Name.prototype.capitalize;
|
|
111
|
-
Name.prototype.decap = Name.prototype.decapitalize;
|
|
112
|
-
Name.prototype.norm = Name.prototype.normalize;
|
|
113
|
-
Name.prototype.stats = Name.prototype.describe;
|
|
114
|
-
Name.prototype.inits = Name.prototype.getInitials;
|
|
115
|
-
//# 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;AACzC,kCAA2D;AAE3D;;;;GAIG;AACH,MAAa,IAAI;IAKb;;;;;OAKG;IACH,YAAmB,KAAa,EAAS,IAAW,EAAE,GAAuB;QAA1D,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,CAAC,CAAC;QAC3B,IAAI,CAAC,CAAC,GAAG;YAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACJ,OAAO,IAAI,eAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,QAAQ;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IAC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OAGG;IACH,KAAK,CAAC,YAAuB;QACzB,OAAO,qBAAc,CAAC,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,MAAM;QACF,OAAO,uBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACJ;AApGD,oBAoGC;AAaD,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;AAC/C,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;AACnD,IAAI,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;AAC/C,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;AAC/C,IAAI,CAAC,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the statistical summary of a string representation
|
|
3
|
-
* @class
|
|
4
|
-
*/
|
|
5
|
-
export declare class Summary {
|
|
6
|
-
private namon;
|
|
7
|
-
distribution: {
|
|
8
|
-
[key: string]: number;
|
|
9
|
-
};
|
|
10
|
-
count: number;
|
|
11
|
-
frequency: number;
|
|
12
|
-
top: string;
|
|
13
|
-
unique: number;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a `Summary` of a given string of alphabetical characters
|
|
16
|
-
* @param namon piece of name
|
|
17
|
-
* @param restrictions a set of undesired characters
|
|
18
|
-
*/
|
|
19
|
-
constructor(namon: string, restrictions?: string[]);
|
|
20
|
-
/**
|
|
21
|
-
* Returns a string representation of the summary
|
|
22
|
-
*/
|
|
23
|
-
tostring(): string;
|
|
24
|
-
private compute;
|
|
25
|
-
private groupByChar;
|
|
26
|
-
}
|
|
@@ -1,61 +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`, `distrib : ${Object.entries(this.distribution).map(e => `${e[1]}${e[0]}`).join(',')} \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.distribution = freqs;
|
|
45
|
-
this.count = count;
|
|
46
|
-
this.frequency = maxfreq;
|
|
47
|
-
this.top = top;
|
|
48
|
-
this.unique = uniq;
|
|
49
|
-
}
|
|
50
|
-
groupByChar() {
|
|
51
|
-
const frequencies = {};
|
|
52
|
-
for (const char of this.namon.toUpperCase())
|
|
53
|
-
if (Object.keys(frequencies).includes(char))
|
|
54
|
-
frequencies[char] += 1;
|
|
55
|
-
else
|
|
56
|
-
frequencies[char] = 1;
|
|
57
|
-
return frequencies;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.Summary = Summary;
|
|
61
|
-
//# 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;IAOhB;;;;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,EAC9B,cAAc,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAC5F,CAAC;IACN,CAAC;IAEO,OAAO,CAAC,eAAyB,EAAE;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