@shaxpir/duiduidui-models 1.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 +1 -0
- package/decs.d.ts +87 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/models/OutboundMessage.d.ts +18 -0
- package/dist/models/OutboundMessage.js +25 -0
- package/dist/models/content/Activity.d.ts +10 -0
- package/dist/models/content/Activity.js +2 -0
- package/dist/models/content/ArrayView.d.ts +26 -0
- package/dist/models/content/ArrayView.js +174 -0
- package/dist/models/content/Billing.d.ts +144 -0
- package/dist/models/content/Billing.js +418 -0
- package/dist/models/content/Book.d.ts +77 -0
- package/dist/models/content/Book.js +407 -0
- package/dist/models/content/Category.d.ts +16 -0
- package/dist/models/content/Category.js +20 -0
- package/dist/models/content/Checkpointable.d.ts +21 -0
- package/dist/models/content/Checkpointable.js +156 -0
- package/dist/models/content/Comment.d.ts +19 -0
- package/dist/models/content/Comment.js +53 -0
- package/dist/models/content/ConceptArt.d.ts +31 -0
- package/dist/models/content/ConceptArt.js +84 -0
- package/dist/models/content/Content.d.ts +52 -0
- package/dist/models/content/Content.js +61 -0
- package/dist/models/content/ContentKind.d.ts +10 -0
- package/dist/models/content/ContentKind.js +16 -0
- package/dist/models/content/Context.d.ts +28 -0
- package/dist/models/content/Context.js +162 -0
- package/dist/models/content/DevEnv.d.ts +5 -0
- package/dist/models/content/DevEnv.js +9 -0
- package/dist/models/content/Device.d.ts +24 -0
- package/dist/models/content/Device.js +62 -0
- package/dist/models/content/Dictionary.d.ts +31 -0
- package/dist/models/content/Dictionary.js +5 -0
- package/dist/models/content/DictionaryEntry.d.ts +20 -0
- package/dist/models/content/DictionaryEntry.js +2 -0
- package/dist/models/content/ElasticModel.d.ts +149 -0
- package/dist/models/content/ElasticModel.js +179 -0
- package/dist/models/content/Environment.d.ts +61 -0
- package/dist/models/content/Environment.js +124 -0
- package/dist/models/content/ExportOptions.d.ts +64 -0
- package/dist/models/content/ExportOptions.js +213 -0
- package/dist/models/content/Folder.d.ts +16 -0
- package/dist/models/content/Folder.js +33 -0
- package/dist/models/content/Fragment.d.ts +54 -0
- package/dist/models/content/Fragment.js +181 -0
- package/dist/models/content/GeoLocation.d.ts +4 -0
- package/dist/models/content/GeoLocation.js +2 -0
- package/dist/models/content/Hanzi.d.ts +21 -0
- package/dist/models/content/Hanzi.js +2 -0
- package/dist/models/content/HighlightRule.d.ts +9 -0
- package/dist/models/content/HighlightRule.js +2 -0
- package/dist/models/content/Manifest.d.ts +42 -0
- package/dist/models/content/Manifest.js +114 -0
- package/dist/models/content/Media.d.ts +32 -0
- package/dist/models/content/Media.js +98 -0
- package/dist/models/content/Metric.d.ts +46 -0
- package/dist/models/content/Metric.js +183 -0
- package/dist/models/content/Migration.d.ts +68 -0
- package/dist/models/content/Migration.js +155 -0
- package/dist/models/content/Model.d.ts +45 -0
- package/dist/models/content/Model.js +280 -0
- package/dist/models/content/Permissions.d.ts +7 -0
- package/dist/models/content/Permissions.js +20 -0
- package/dist/models/content/Phrase.d.ts +8 -0
- package/dist/models/content/Phrase.js +2 -0
- package/dist/models/content/Placeholder.d.ts +8 -0
- package/dist/models/content/Placeholder.js +36 -0
- package/dist/models/content/Profile.d.ts +30 -0
- package/dist/models/content/Profile.js +95 -0
- package/dist/models/content/RichText.d.ts +58 -0
- package/dist/models/content/RichText.js +79 -0
- package/dist/models/content/Session.d.ts +39 -0
- package/dist/models/content/Session.js +173 -0
- package/dist/models/content/Speech.d.ts +67 -0
- package/dist/models/content/Speech.js +97 -0
- package/dist/models/content/Stub.d.ts +24 -0
- package/dist/models/content/Stub.js +179 -0
- package/dist/models/content/Time.d.ts +56 -0
- package/dist/models/content/Time.js +295 -0
- package/dist/models/content/User.d.ts +36 -0
- package/dist/models/content/User.js +95 -0
- package/dist/models/content/Workspace.d.ts +71 -0
- package/dist/models/content/Workspace.js +237 -0
- package/dist/models/content/index.d.ts +36 -0
- package/dist/models/content/index.js +53 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +21 -0
- package/dist/models/legacy/LegacyBodyFormat.d.ts +9 -0
- package/dist/models/legacy/LegacyBodyFormat.js +2 -0
- package/dist/models/legacy/LegacyComment.d.ts +12 -0
- package/dist/models/legacy/LegacyComment.js +2 -0
- package/dist/models/legacy/LegacyContent.d.ts +53 -0
- package/dist/models/legacy/LegacyContent.js +55 -0
- package/dist/models/legacy/LegacyConversion.d.ts +55 -0
- package/dist/models/legacy/LegacyConversion.js +401 -0
- package/dist/models/legacy/LegacyFragment.d.ts +21 -0
- package/dist/models/legacy/LegacyFragment.js +2 -0
- package/dist/models/legacy/LegacyLocator.d.ts +8 -0
- package/dist/models/legacy/LegacyLocator.js +31 -0
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +16 -0
- package/dist/models/legacy/LegacyOutboundMessage.js +13 -0
- package/dist/models/legacy/LegacyPicture.d.ts +14 -0
- package/dist/models/legacy/LegacyPicture.js +2 -0
- package/dist/models/legacy/LegacyProfile.d.ts +9 -0
- package/dist/models/legacy/LegacyProfile.js +2 -0
- package/dist/models/legacy/LegacySession.d.ts +41 -0
- package/dist/models/legacy/LegacySession.js +35 -0
- package/dist/models/legacy/LegacyStory.d.ts +23 -0
- package/dist/models/legacy/LegacyStory.js +2 -0
- package/dist/models/legacy/LegacyStub.d.ts +15 -0
- package/dist/models/legacy/LegacyStub.js +2 -0
- package/dist/models/legacy/LegacyTransaction.d.ts +14 -0
- package/dist/models/legacy/LegacyTransaction.js +49 -0
- package/dist/models/legacy/LegacyUser.d.ts +28 -0
- package/dist/models/legacy/LegacyUser.js +32 -0
- package/dist/models/legacy/LegacyWorkspace.d.ts +23 -0
- package/dist/models/legacy/LegacyWorkspace.js +6 -0
- package/dist/models/legacy/index.d.ts +15 -0
- package/dist/models/legacy/index.js +32 -0
- package/dist/models/markup/BodyFormat.d.ts +14 -0
- package/dist/models/markup/BodyFormat.js +190 -0
- package/dist/models/markup/ChangeModel.d.ts +22 -0
- package/dist/models/markup/ChangeModel.js +107 -0
- package/dist/models/markup/DeltaOps.d.ts +5 -0
- package/dist/models/markup/DeltaOps.js +74 -0
- package/dist/models/markup/HtmlMarkup.d.ts +4 -0
- package/dist/models/markup/HtmlMarkup.js +21 -0
- package/dist/models/markup/Operation.d.ts +32 -0
- package/dist/models/markup/Operation.js +194 -0
- package/dist/models/markup/TextEditOps.d.ts +9 -0
- package/dist/models/markup/TextEditOps.js +50 -0
- package/dist/models/markup/index.d.ts +6 -0
- package/dist/models/markup/index.js +23 -0
- package/dist/repo/ConnectionListener.d.ts +9 -0
- package/dist/repo/ConnectionListener.js +21 -0
- package/dist/repo/PermissiveJson1.d.ts +58 -0
- package/dist/repo/PermissiveJson1.js +39 -0
- package/dist/repo/ShareSync.d.ts +60 -0
- package/dist/repo/ShareSync.js +348 -0
- package/dist/repo/index.d.ts +3 -0
- package/dist/repo/index.js +20 -0
- package/dist/util/Async.d.ts +8 -0
- package/dist/util/Async.js +18 -0
- package/dist/util/Base62.d.ts +6 -0
- package/dist/util/Base62.js +47 -0
- package/dist/util/BinarySearch.d.ts +7 -0
- package/dist/util/BinarySearch.js +46 -0
- package/dist/util/CachingHasher.d.ts +8 -0
- package/dist/util/CachingHasher.js +41 -0
- package/dist/util/Color.d.ts +32 -0
- package/dist/util/Color.js +204 -0
- package/dist/util/Dispatch.d.ts +15 -0
- package/dist/util/Dispatch.js +79 -0
- package/dist/util/EditDistance.d.ts +13 -0
- package/dist/util/EditDistance.js +184 -0
- package/dist/util/Encryption.d.ts +5 -0
- package/dist/util/Encryption.js +2 -0
- package/dist/util/Logging.d.ts +108 -0
- package/dist/util/Logging.js +412 -0
- package/dist/util/NumberFormat.d.ts +14 -0
- package/dist/util/NumberFormat.js +224 -0
- package/dist/util/Struct.d.ts +4 -0
- package/dist/util/Struct.js +15 -0
- package/dist/util/Template.d.ts +16 -0
- package/dist/util/Template.js +128 -0
- package/dist/util/Text.d.ts +45 -0
- package/dist/util/Text.js +243 -0
- package/dist/util/Tuples.d.ts +9 -0
- package/dist/util/Tuples.js +135 -0
- package/dist/util/Validate.d.ts +4 -0
- package/dist/util/Validate.js +11 -0
- package/dist/util/Vocabulary.d.ts +3 -0
- package/dist/util/Vocabulary.js +35 -0
- package/dist/util/index.d.ts +16 -0
- package/dist/util/index.js +33 -0
- package/lib/models/content/ArrayView.ts +203 -0
- package/lib/models/content/Billing.ts +558 -0
- package/lib/models/content/Content.ts +110 -0
- package/lib/models/content/ContentKind.ts +14 -0
- package/lib/models/content/DevEnv.ts +5 -0
- package/lib/models/content/Device.ts +86 -0
- package/lib/models/content/DictionaryEntry.ts +22 -0
- package/lib/models/content/GeoLocation.ts +4 -0
- package/lib/models/content/Hanzi.ts +25 -0
- package/lib/models/content/Manifest.ts +162 -0
- package/lib/models/content/Media.ts +126 -0
- package/lib/models/content/Model.ts +327 -0
- package/lib/models/content/Permissions.ts +21 -0
- package/lib/models/content/Phrase.ts +10 -0
- package/lib/models/content/Profile.ts +119 -0
- package/lib/models/content/Time.ts +328 -0
- package/lib/models/content/User.ts +130 -0
- package/lib/models/markup/ChangeModel.ts +95 -0
- package/lib/models/markup/DeltaOps.ts +71 -0
- package/lib/models/markup/Operation.ts +215 -0
- package/lib/models/markup/TextEditOps.ts +50 -0
- package/lib/repo/ConnectionListener.ts +25 -0
- package/lib/repo/PermissiveJson1.ts +14 -0
- package/lib/repo/ShareSync.ts +390 -0
- package/lib/util/Base62.ts +47 -0
- package/lib/util/CachingHasher.ts +38 -0
- package/lib/util/Dispatch.ts +92 -0
- package/lib/util/Encryption.ts +5 -0
- package/lib/util/Logging.ts +568 -0
- package/lib/util/NumberFormat.ts +194 -0
- package/lib/util/Struct.ts +14 -0
- package/lib/util/Tuples.ts +131 -0
- package/package.json +41 -0
- package/tsconfig.json +25 -0
- package/tslint.json +46 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Template = exports.TemplateParser = void 0;
|
|
4
|
+
const HtmlMarkup_1 = require("../models/markup/HtmlMarkup");
|
|
5
|
+
class TemplateParser {
|
|
6
|
+
static parse(text) {
|
|
7
|
+
let chunks = [];
|
|
8
|
+
let lastEndIndex = 0;
|
|
9
|
+
let match;
|
|
10
|
+
while ((match = TemplateParser.TAG_PATTERN.exec(text)) !== null) {
|
|
11
|
+
let tagText = match[0];
|
|
12
|
+
let index = match.index;
|
|
13
|
+
if (index > lastEndIndex) {
|
|
14
|
+
let textBeforeTag = text.substring(lastEndIndex, index);
|
|
15
|
+
chunks.push(textBeforeTag);
|
|
16
|
+
}
|
|
17
|
+
chunks.push(tagText);
|
|
18
|
+
lastEndIndex = index + tagText.length;
|
|
19
|
+
}
|
|
20
|
+
if (lastEndIndex < text.length) {
|
|
21
|
+
let textAfterTag = text.substring(lastEndIndex);
|
|
22
|
+
chunks.push(textAfterTag);
|
|
23
|
+
}
|
|
24
|
+
return TemplateParser.fromChunks(chunks, null, false);
|
|
25
|
+
}
|
|
26
|
+
static fromChunks(chunks, name, negated) {
|
|
27
|
+
let parts = [];
|
|
28
|
+
for (let i = 0, len = chunks.length; i < len; i++) {
|
|
29
|
+
let chunk = chunks[i];
|
|
30
|
+
if (!chunk.startsWith("{")) {
|
|
31
|
+
parts.push(new StringLiteratal(chunk));
|
|
32
|
+
}
|
|
33
|
+
else if (chunk.startsWith("{{{")) {
|
|
34
|
+
if (chunk.endsWith("}}}")) {
|
|
35
|
+
let name = chunk.substring(3, chunk.length - 3);
|
|
36
|
+
if (name.startsWith("/") || name.startsWith("^") || name.startsWith("#")) {
|
|
37
|
+
throw new Error("illegal name for triple-braced template-tag: " + chunk);
|
|
38
|
+
}
|
|
39
|
+
parts.push(new TemplateTag(name, false));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error("mismatched braces in template-tag: " + chunk);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (chunk.endsWith("}}}")) {
|
|
47
|
+
throw new Error("mismatched braces in template-tag: " + chunk);
|
|
48
|
+
}
|
|
49
|
+
else if (chunk.startsWith("{{#") || chunk.startsWith("{{^")) {
|
|
50
|
+
let name = chunk.substring(3, chunk.length - 2);
|
|
51
|
+
let negated = chunk.startsWith("{{^");
|
|
52
|
+
let endIndex = TemplateParser.findEndIndex(chunks, name, i);
|
|
53
|
+
if (endIndex - i > 1) {
|
|
54
|
+
let subChunks = chunks.slice(i + 1, endIndex);
|
|
55
|
+
let template = TemplateParser.fromChunks(subChunks, name, negated);
|
|
56
|
+
parts.push(template);
|
|
57
|
+
}
|
|
58
|
+
i = endIndex;
|
|
59
|
+
}
|
|
60
|
+
else if (chunk.startsWith("{{/")) {
|
|
61
|
+
throw new Error("unmatched end-tag: " + chunk);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
let name = chunk.substring(2, chunk.length - 2);
|
|
65
|
+
parts.push(new TemplateTag(name, true));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return new Template(parts, name, negated);
|
|
70
|
+
}
|
|
71
|
+
static findEndIndex(chunks, name, startIndex) {
|
|
72
|
+
for (let i = startIndex + 1; i < chunks.length; i++) {
|
|
73
|
+
let chunk = chunks[i];
|
|
74
|
+
if (chunk === "{{/" + name + "}}") {
|
|
75
|
+
return i;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
throw new Error("can't find end-index for chunk: " + chunks[startIndex]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.TemplateParser = TemplateParser;
|
|
82
|
+
TemplateParser.TAG_PATTERN = /\{\{.+?\}?\}\}/g;
|
|
83
|
+
class Template {
|
|
84
|
+
constructor(parts, name, negated) {
|
|
85
|
+
this.parts = parts;
|
|
86
|
+
this.name = name;
|
|
87
|
+
this.negated = negated;
|
|
88
|
+
}
|
|
89
|
+
render(params) {
|
|
90
|
+
let result = "";
|
|
91
|
+
if (this.name == null ||
|
|
92
|
+
(params.hasOwnProperty(this.name) && params[this.name] === !this.negated)) {
|
|
93
|
+
for (let i = 0, len = this.parts.length; i < len; i++) {
|
|
94
|
+
let part = this.parts[i];
|
|
95
|
+
result += part.render(params);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Template = Template;
|
|
102
|
+
class StringLiteratal {
|
|
103
|
+
constructor(value) {
|
|
104
|
+
this.value = value;
|
|
105
|
+
}
|
|
106
|
+
render(params) {
|
|
107
|
+
return this.value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class TemplateTag {
|
|
111
|
+
constructor(name, escapeHtml) {
|
|
112
|
+
this.name = name;
|
|
113
|
+
this.escapeHtml = escapeHtml;
|
|
114
|
+
}
|
|
115
|
+
render(params) {
|
|
116
|
+
if (params.hasOwnProperty(this.name)) {
|
|
117
|
+
let value = params[this.name];
|
|
118
|
+
if (value !== null) {
|
|
119
|
+
let text = "" + value;
|
|
120
|
+
if (this.escapeHtml) {
|
|
121
|
+
text = HtmlMarkup_1.HtmlMarkup.escapeText(text);
|
|
122
|
+
}
|
|
123
|
+
return text;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare class Text {
|
|
2
|
+
private static readonly WORD_START_CHAR_CLASS;
|
|
3
|
+
private static readonly WORD_MIDDLE_CHAR_CLASS;
|
|
4
|
+
private static readonly WORD_END_CHAR_CLASS;
|
|
5
|
+
private static readonly APOSTROPHE_CHAR_CLASS;
|
|
6
|
+
private static readonly WORD_POST_APOS_CHAR_CLASS;
|
|
7
|
+
private static readonly WORD_BOUNDARY_BEFORE;
|
|
8
|
+
private static readonly WORD_BOUNDARY_AFTER;
|
|
9
|
+
private static readonly WORD_PATTERN;
|
|
10
|
+
static readonly WORD_REGEX: RegExp;
|
|
11
|
+
private static readonly NON_WORD_CHARS;
|
|
12
|
+
static countWords(text: string): number;
|
|
13
|
+
static tokenizeWords(text: string, keepSeparators: boolean): string[];
|
|
14
|
+
static getUniqueWords(text: string): string[];
|
|
15
|
+
static capitalizeWords(text: string): string;
|
|
16
|
+
static normalizeText(text: string): string;
|
|
17
|
+
static normalizeDashes(text: string): string;
|
|
18
|
+
static makeCurlyQuotes(text: string): string;
|
|
19
|
+
static normalizeApostrophes(text: string): string;
|
|
20
|
+
static removeDashes(text: string): string;
|
|
21
|
+
static removeApostrophes(text: string): string;
|
|
22
|
+
static removePosessive(text: string): string;
|
|
23
|
+
static removePlural(word: string): string;
|
|
24
|
+
static removeSuffixes(word: string, suffixes: string[]): string;
|
|
25
|
+
static stripNonWordChars(text: string): string;
|
|
26
|
+
static endsWithAnySuffix(text: string, suffixes: string[]): boolean;
|
|
27
|
+
static endsWithWordChar(text: string): boolean;
|
|
28
|
+
static isWordChar(c: string): boolean;
|
|
29
|
+
static isAllWordChars(text: string): boolean;
|
|
30
|
+
static hasAnyWordChars(text: string): boolean;
|
|
31
|
+
static isPunctuation(c: string): boolean;
|
|
32
|
+
static isAllPunctuation(text: string): boolean;
|
|
33
|
+
static hasAnyPunctuation(text: string): boolean;
|
|
34
|
+
static isWhitspace(c: string): boolean;
|
|
35
|
+
static isAllWhitspace(text: string): boolean;
|
|
36
|
+
static hasAnyWhitspace(text: string): boolean;
|
|
37
|
+
static isDigit(c: string): boolean;
|
|
38
|
+
static isAllDigits(text: string): boolean;
|
|
39
|
+
static hasAnyDigits(text: string): boolean;
|
|
40
|
+
static isCapitalLetter(c: string): boolean;
|
|
41
|
+
static isAllCapitalLetters(text: string): boolean;
|
|
42
|
+
static hasAnyCapitalLetters(text: string): boolean;
|
|
43
|
+
private static allCharsMatch;
|
|
44
|
+
private static anyCharsMatch;
|
|
45
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Text = void 0;
|
|
27
|
+
const pluralize = __importStar(require("pluralize"));
|
|
28
|
+
class Text {
|
|
29
|
+
static countWords(text) {
|
|
30
|
+
let wordCount = 0;
|
|
31
|
+
if (text.length && text.length > 0) {
|
|
32
|
+
let match;
|
|
33
|
+
while ((match = Text.WORD_REGEX.exec(text)) !== null) {
|
|
34
|
+
wordCount++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return wordCount;
|
|
38
|
+
}
|
|
39
|
+
static tokenizeWords(text, keepSeparators) {
|
|
40
|
+
let chunks = [];
|
|
41
|
+
let prevMatchEnd = 0;
|
|
42
|
+
if (text.length && text.length > 0) {
|
|
43
|
+
let match;
|
|
44
|
+
while ((match = Text.WORD_REGEX.exec(text)) !== null) {
|
|
45
|
+
let matchText = match[0];
|
|
46
|
+
let matchStart = match.index;
|
|
47
|
+
let matchEnd = matchStart + matchText.length;
|
|
48
|
+
if (keepSeparators && matchStart - prevMatchEnd > 0) {
|
|
49
|
+
let prevText = text.substring(prevMatchEnd, matchStart);
|
|
50
|
+
chunks.push(prevText);
|
|
51
|
+
}
|
|
52
|
+
chunks.push(matchText);
|
|
53
|
+
prevMatchEnd = matchEnd;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (keepSeparators && prevMatchEnd < text.length) {
|
|
57
|
+
let textAfterFinalWord = text.substring(prevMatchEnd);
|
|
58
|
+
chunks.push(textAfterFinalWord);
|
|
59
|
+
}
|
|
60
|
+
return chunks;
|
|
61
|
+
}
|
|
62
|
+
static getUniqueWords(text) {
|
|
63
|
+
let words = [];
|
|
64
|
+
let map = {};
|
|
65
|
+
let match;
|
|
66
|
+
while ((match = Text.WORD_REGEX.exec(text)) !== null) {
|
|
67
|
+
let word = match[0];
|
|
68
|
+
if (!map.hasOwnProperty(word)) {
|
|
69
|
+
map[word] = true;
|
|
70
|
+
words.push(word);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return words;
|
|
74
|
+
}
|
|
75
|
+
static capitalizeWords(text) {
|
|
76
|
+
return text.toLowerCase().replace(/\b[a-z]/g, function (letter) {
|
|
77
|
+
return letter.toUpperCase();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
static normalizeText(text) {
|
|
81
|
+
text = Text.normalizeDashes(text);
|
|
82
|
+
text = Text.normalizeApostrophes(text);
|
|
83
|
+
return text;
|
|
84
|
+
}
|
|
85
|
+
static normalizeDashes(text) {
|
|
86
|
+
return text.replace(/[\u2010-\u2015]/g, "-");
|
|
87
|
+
}
|
|
88
|
+
static makeCurlyQuotes(text) {
|
|
89
|
+
text = text.replace(/(^|\s+)"/gmu, "$1“");
|
|
90
|
+
text = text.replace(/"(\\s+|$)/gmu, "”$1");
|
|
91
|
+
text = text.replace(/"$/gmu, "”");
|
|
92
|
+
text = text.replace(/(\p{L})"([.,:;?!)])/gmu, "$1”$2");
|
|
93
|
+
text = text.replace(/(^|\s+)'/gmu, "$1‘");
|
|
94
|
+
text = text.replace(/'/gmu, "’");
|
|
95
|
+
return text;
|
|
96
|
+
}
|
|
97
|
+
static normalizeApostrophes(text) {
|
|
98
|
+
return text.replace(/[\u2018\u2019]/g, "'");
|
|
99
|
+
}
|
|
100
|
+
static removeDashes(text) {
|
|
101
|
+
return text.replace(/[\-\u2010-\u2015]/g, "");
|
|
102
|
+
}
|
|
103
|
+
static removeApostrophes(text) {
|
|
104
|
+
return text.replace(/['\u2018\u2019]/g, "");
|
|
105
|
+
}
|
|
106
|
+
static removePosessive(text) {
|
|
107
|
+
return Text.normalizeApostrophes(text).replace(/'s?$/, "");
|
|
108
|
+
}
|
|
109
|
+
static removePlural(word) {
|
|
110
|
+
return pluralize.singular(word);
|
|
111
|
+
}
|
|
112
|
+
static removeSuffixes(word, suffixes) {
|
|
113
|
+
for (let i = 0, len = suffixes.length; i < len; i++) {
|
|
114
|
+
let suffix = suffixes[i];
|
|
115
|
+
// We will only remove suffixes from root words having three or more letters.
|
|
116
|
+
if (word.length > suffix.length + 3) {
|
|
117
|
+
// The suffix must occur at the end
|
|
118
|
+
let suffixStart = word.indexOf(suffix);
|
|
119
|
+
if (suffixStart === word.length - suffix.length) {
|
|
120
|
+
// Remove the actual suffix.
|
|
121
|
+
word = word.substring(0, suffixStart);
|
|
122
|
+
// If the word ends in a duble-consonant, remove the last char too.
|
|
123
|
+
let lastLetter = word.charAt(word.length - 1);
|
|
124
|
+
let prevLastLetter = word.charAt(word.length - 2);
|
|
125
|
+
if (lastLetter === prevLastLetter) {
|
|
126
|
+
word = word.substring(0, word.length - 1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return word;
|
|
132
|
+
}
|
|
133
|
+
static stripNonWordChars(text) {
|
|
134
|
+
return text.replace(Text.NON_WORD_CHARS, "");
|
|
135
|
+
}
|
|
136
|
+
static endsWithAnySuffix(text, suffixes) {
|
|
137
|
+
for (let i = 0, len = suffixes.length; i < len; i++) {
|
|
138
|
+
let suffix = suffixes[i];
|
|
139
|
+
if (text.lastIndexOf(suffix) === text.length - suffix.length) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
static endsWithWordChar(text) {
|
|
146
|
+
const lastChar = text.charAt(text.length - 1);
|
|
147
|
+
return text.length > 0 && !Text.isPunctuation(lastChar) && Text.isWordChar(lastChar);
|
|
148
|
+
}
|
|
149
|
+
static isWordChar(c) {
|
|
150
|
+
return c.length === 1 &&
|
|
151
|
+
(c >= 'a' && c <= 'z') ||
|
|
152
|
+
(c >= 'A' && c <= 'Z') ||
|
|
153
|
+
(c >= '0' && c <= '9') ||
|
|
154
|
+
"-'‘’ÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜäëïöüçÇߨøÅ寿ÞþÐðĀĒĪŌŪȲǢāēīōūȳǣ".indexOf(c) >= 0;
|
|
155
|
+
}
|
|
156
|
+
static isAllWordChars(text) {
|
|
157
|
+
return Text.allCharsMatch(text, Text.isWordChar);
|
|
158
|
+
}
|
|
159
|
+
static hasAnyWordChars(text) {
|
|
160
|
+
return Text.anyCharsMatch(text, Text.isWordChar);
|
|
161
|
+
}
|
|
162
|
+
static isPunctuation(c) {
|
|
163
|
+
return c.length === 1 && ".,'?!-:;|\\\"<>/[]{}()_+=@#$%^&*".indexOf(c) >= 0;
|
|
164
|
+
}
|
|
165
|
+
static isAllPunctuation(text) {
|
|
166
|
+
return Text.allCharsMatch(text, Text.isPunctuation);
|
|
167
|
+
}
|
|
168
|
+
static hasAnyPunctuation(text) {
|
|
169
|
+
return Text.anyCharsMatch(text, Text.isPunctuation);
|
|
170
|
+
}
|
|
171
|
+
static isWhitspace(c) {
|
|
172
|
+
return c.length === 1 && " \t\r\n".indexOf(c) >= 0;
|
|
173
|
+
}
|
|
174
|
+
static isAllWhitspace(text) {
|
|
175
|
+
return Text.allCharsMatch(text, Text.isWhitspace);
|
|
176
|
+
}
|
|
177
|
+
static hasAnyWhitspace(text) {
|
|
178
|
+
return Text.anyCharsMatch(text, Text.isWhitspace);
|
|
179
|
+
}
|
|
180
|
+
static isDigit(c) {
|
|
181
|
+
return c.length === 1 && c >= '0' && c <= '9';
|
|
182
|
+
}
|
|
183
|
+
static isAllDigits(text) {
|
|
184
|
+
return Text.allCharsMatch(text, Text.isDigit);
|
|
185
|
+
}
|
|
186
|
+
static hasAnyDigits(text) {
|
|
187
|
+
return Text.anyCharsMatch(text, Text.isDigit);
|
|
188
|
+
}
|
|
189
|
+
static isCapitalLetter(c) {
|
|
190
|
+
return c.length === 1 && (c >= 'A' && c <= 'Z') || "ÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÄËÏÖÜÇߨůÞÐĀĒĪŌŪȲǢ".indexOf(c) >= 0;
|
|
191
|
+
}
|
|
192
|
+
static isAllCapitalLetters(text) {
|
|
193
|
+
return Text.allCharsMatch(text, Text.isCapitalLetter);
|
|
194
|
+
}
|
|
195
|
+
static hasAnyCapitalLetters(text) {
|
|
196
|
+
return Text.anyCharsMatch(text, Text.isCapitalLetter);
|
|
197
|
+
}
|
|
198
|
+
static allCharsMatch(text, predicate) {
|
|
199
|
+
if (text.length > 0) {
|
|
200
|
+
for (let i = 0, len = text.length; i < len; i++) {
|
|
201
|
+
let c = text.charAt(i);
|
|
202
|
+
if (!predicate(c)) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
static anyCharsMatch(text, predicate) {
|
|
211
|
+
for (let i = 0, len = text.length; i < len; i++) {
|
|
212
|
+
let c = text.charAt(i);
|
|
213
|
+
if (predicate(c)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.Text = Text;
|
|
221
|
+
Text.WORD_START_CHAR_CLASS = "[a-zA-Z0-9B̌b̌F̌f̌ĞğJ̌M̌m̌ńọP̌p̌Q̌q̌V̌v̌W̌w̌X̌x̌Y̌y̌ßÀàÁáÂâÃãÄäÅ寿ÇçÈèÉéÊêÊ̌ê̌ËëÌìÍíÎîÏïİi̇ıÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜüÝýÞþĀāČčČ̣č̣ĎďĒēĚěĪīĽľŁłŇňŌōŘřŘ̩ř̩ŞşŠšŤťŪūŻżŽžǍǎǏǐǑǒǓǔǙǚǢǣǦǧǨǩǮǯǰȘșȞȟȲȳṦṧẾếỄễỌọ́]";
|
|
222
|
+
Text.WORD_MIDDLE_CHAR_CLASS = "[a-zA-Z0-9B̌b̌F̌f̌ĞğJ̌M̌m̌ńọP̌p̌Q̌q̌V̌v̌W̌w̌X̌x̌Y̌y̌ßÀàÁáÂâÃãÄäÅ寿ÇçÈèÉéÊêÊ̌ê̌ËëÌìÍíÎîÏïİi̇ıÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜüÝýÞþĀāČčČ̣č̣ĎďĒēĚěĪīĽľŁłŇňŌōŘřŘ̩ř̩ŞşŠšŤťŪūŻżŽžǍǎǏǐǑǒǓǔǙǚǢǣǦǧǨǩǮǯǰȘșȞȟȲȳṦṧẾếỄễỌọ́\\.\\-]";
|
|
223
|
+
Text.WORD_END_CHAR_CLASS = "[a-zA-Z0-9B̌b̌F̌f̌ĞğJ̌M̌m̌ńọP̌p̌Q̌q̌V̌v̌W̌w̌X̌x̌Y̌y̌ßÀàÁáÂâÃãÄäÅ寿ÇçÈèÉéÊêÊ̌ê̌ËëÌìÍíÎîÏïİi̇ıÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜüÝýÞþĀāČčČ̣č̣ĎďĒēĚěĪīĽľŁłŇňŌōŘřŘ̩ř̩ŞşŠšŤťŪūŻżŽžǍǎǏǐǑǒǓǔǙǚǢǣǦǧǨǩǮǯǰȘșȞȟȲȳṦṧẾếỄễỌọ́]";
|
|
224
|
+
Text.APOSTROPHE_CHAR_CLASS = "[\u0027\u2018\u2019]";
|
|
225
|
+
Text.WORD_POST_APOS_CHAR_CLASS = "[a-zA-ZB̌b̌F̌Ğğf̌J̌M̌m̌ńọP̌p̌Q̌q̌V̌v̌W̌w̌X̌x̌Y̌y̌ßÀàÁáÂâÃãÄäÅ寿ÇçÈèÉéÊêÊ̌ê̌ËëÌìÍíÎîÏïİi̇ıÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜüÝýÞþĀāČčČ̣č̣ĎďĒēĚěĪīĽľŁłŇňŌōŘřŘ̩ř̩ŞşŠšŤťŪūŻżŽžǍǎǏǐǑǒǓǔǙǚǢǣǦǧǨǩǮǯǰȘșȞȟȲȳṦṧẾếỄễỌọ́]";
|
|
226
|
+
// Since we need to match on unicode text, we can't use the normal \b word boundary assertion,
|
|
227
|
+
// because it only matches on ASCII word boundaries. Instead, we use our own word boundary
|
|
228
|
+
// assertions that match on unicode word boundaries, based on negative lookbehind and lookahead.
|
|
229
|
+
Text.WORD_BOUNDARY_BEFORE = "(?<![\\p{Letter}\\p{Number}])";
|
|
230
|
+
Text.WORD_BOUNDARY_AFTER = "(?![\\p{Letter}\\p{Number}])";
|
|
231
|
+
Text.WORD_PATTERN = Text.WORD_BOUNDARY_BEFORE +
|
|
232
|
+
Text.WORD_START_CHAR_CLASS +
|
|
233
|
+
"(?:" +
|
|
234
|
+
Text.WORD_MIDDLE_CHAR_CLASS + "*" +
|
|
235
|
+
Text.WORD_END_CHAR_CLASS +
|
|
236
|
+
")?" +
|
|
237
|
+
"(?:" +
|
|
238
|
+
Text.APOSTROPHE_CHAR_CLASS +
|
|
239
|
+
Text.WORD_POST_APOS_CHAR_CLASS + "+" +
|
|
240
|
+
")*" +
|
|
241
|
+
Text.WORD_BOUNDARY_AFTER;
|
|
242
|
+
Text.WORD_REGEX = new RegExp(Text.WORD_PATTERN, "gu");
|
|
243
|
+
Text.NON_WORD_CHARS = /[^a-zA-Z0-9B̌b̌F̌f̌ĞğJ̌M̌m̌ńọP̌p̌Q̌q̌V̌v̌W̌w̌X̌x̌Y̌y̌ßÀàÁáÂâÃãÄäÅ寿ÇçÈèÉéÊêÊ̌ê̌ËëÌìÍíÎîÏïİi̇ıÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜüÝýÞþĀāČčČ̣č̣ĎďĒēĚěĪīĽľŁłŇňŌōŘřŘ̩ř̩ŞşŠšŤťŪūŻżŽžǍǎǏǐǑǒǓǔǙǚǢǣǦǧǨǩǮǯǰȘșȞȟȲȳṦṧẾếỄễỌọ́]/g;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JsonPath, PathVal } from "../models/markup/Operation";
|
|
2
|
+
export declare class Tuples {
|
|
3
|
+
static of(value: any): PathVal[];
|
|
4
|
+
static stringifyPath(prefix: string, path: JsonPath): string;
|
|
5
|
+
private static collectFromArray;
|
|
6
|
+
private static collectFromObject;
|
|
7
|
+
private static collectTuplesAtPath;
|
|
8
|
+
private static sort;
|
|
9
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tuples = void 0;
|
|
4
|
+
const Struct_1 = require("./Struct");
|
|
5
|
+
class Tuples {
|
|
6
|
+
static of(value) {
|
|
7
|
+
let tuples = [];
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
Tuples.collectFromArray(tuples, [], value);
|
|
10
|
+
}
|
|
11
|
+
else if (value !== null) {
|
|
12
|
+
const type = typeof (value);
|
|
13
|
+
if (type === "object") {
|
|
14
|
+
Tuples.collectFromObject(tuples, [], value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return Tuples.sort(tuples);
|
|
18
|
+
}
|
|
19
|
+
static stringifyPath(prefix, path) {
|
|
20
|
+
if (prefix == null || prefix.trim() == "") {
|
|
21
|
+
prefix = "$";
|
|
22
|
+
}
|
|
23
|
+
if (!prefix.startsWith("$")) {
|
|
24
|
+
prefix = "$" + prefix;
|
|
25
|
+
}
|
|
26
|
+
let str = prefix;
|
|
27
|
+
for (let i = 0; i < path.length; i++) {
|
|
28
|
+
let pathItem = path[i];
|
|
29
|
+
if (typeof (pathItem) === 'string') {
|
|
30
|
+
str += '.' + pathItem;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
str += '[' + pathItem + ']';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return str;
|
|
37
|
+
}
|
|
38
|
+
static collectFromArray(tuples, path, array) {
|
|
39
|
+
for (let i = 0; i < array.length; i++) {
|
|
40
|
+
path.push(i);
|
|
41
|
+
let item = array[i];
|
|
42
|
+
Tuples.collectTuplesAtPath(tuples, path, item);
|
|
43
|
+
path.pop();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static collectFromObject(tuples, path, object) {
|
|
47
|
+
const keys = Object.keys(object);
|
|
48
|
+
for (let i = 0; i < keys.length; i++) {
|
|
49
|
+
const key = keys[i];
|
|
50
|
+
if (object.hasOwnProperty(key)) {
|
|
51
|
+
path.push(key);
|
|
52
|
+
let item = object[key];
|
|
53
|
+
Tuples.collectTuplesAtPath(tuples, path, item);
|
|
54
|
+
path.pop();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static collectTuplesAtPath(tuples, path, item) {
|
|
59
|
+
if (Struct_1.Struct.equals(item, {}) || Struct_1.Struct.equals(item, [])) {
|
|
60
|
+
tuples.push({ path: Struct_1.Struct.clone(path), val: item });
|
|
61
|
+
}
|
|
62
|
+
else if (Array.isArray(item)) {
|
|
63
|
+
Tuples.collectFromArray(tuples, path, item);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const type = typeof (item);
|
|
67
|
+
if (item === null ||
|
|
68
|
+
type === "string" ||
|
|
69
|
+
type === "number" ||
|
|
70
|
+
type === "boolean") {
|
|
71
|
+
tuples.push({ path: Struct_1.Struct.clone(path), val: item });
|
|
72
|
+
}
|
|
73
|
+
else if (type === "function" || type == "symbol" || type == "bigint" || type === "undefined") {
|
|
74
|
+
throw new Error(`can't create tuple from '${type}' item at path: ${JSON.stringify(path)}`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
Tuples.collectFromObject(tuples, path, item);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static sort(tuples) {
|
|
82
|
+
// NOTE: tuples are sorted ONLY according to their PATH. The val is never considered. This is
|
|
83
|
+
// because we assume there can never be two identical paths anyhow, in a valid JSON tuple array.
|
|
84
|
+
tuples.sort((a, b) => {
|
|
85
|
+
const aPath = a.path;
|
|
86
|
+
const bPath = b.path;
|
|
87
|
+
const aPathLength = aPath.length;
|
|
88
|
+
const bPathLength = bPath.length;
|
|
89
|
+
let length = Math.min(aPathLength, bPathLength);
|
|
90
|
+
for (let i = 0; i < length; i++) {
|
|
91
|
+
const aPathElement = aPath[i];
|
|
92
|
+
const bPathElement = bPath[i];
|
|
93
|
+
const aPathElementType = typeof (aPathElement);
|
|
94
|
+
const bPathElementType = typeof (bPathElement);
|
|
95
|
+
let comparison = 0;
|
|
96
|
+
if (aPathElementType === "string" && bPathElementType === "string") {
|
|
97
|
+
const aString = aPathElement;
|
|
98
|
+
const bString = bPathElement;
|
|
99
|
+
comparison = aString.localeCompare(bString);
|
|
100
|
+
}
|
|
101
|
+
else if (aPathElementType === "number" && bPathElementType === "number") {
|
|
102
|
+
const aNumber = aPathElement;
|
|
103
|
+
const bNumber = bPathElement;
|
|
104
|
+
if (aNumber < bNumber) {
|
|
105
|
+
comparison = -1;
|
|
106
|
+
}
|
|
107
|
+
else if (aNumber > bNumber) {
|
|
108
|
+
comparison = 1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (aPathElementType === "string" && bPathElementType === "number") {
|
|
112
|
+
comparison = -1;
|
|
113
|
+
}
|
|
114
|
+
else if (aPathElementType === "number" && bPathElementType === "string") {
|
|
115
|
+
comparison = 1;
|
|
116
|
+
}
|
|
117
|
+
if (comparison !== 0) {
|
|
118
|
+
return comparison;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (aPathLength < bPathLength) {
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
124
|
+
else if (aPathLength > bPathLength) {
|
|
125
|
+
return 1;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// If we never do want to incorporate value comparisons into sort order, this is where we'd do it.
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return tuples;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.Tuples = Tuples;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validate = void 0;
|
|
4
|
+
class Validate {
|
|
5
|
+
static email(text) {
|
|
6
|
+
return Validate.EMAIL_PATTERN.test(text);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.Validate = Validate;
|
|
10
|
+
// COPIED FROM HERE: http://emailregex.com
|
|
11
|
+
Validate.EMAIL_PATTERN = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vocabulary = void 0;
|
|
4
|
+
class Vocabulary {
|
|
5
|
+
static calculateSizePercentile(wordCount, uniqueCount) {
|
|
6
|
+
// This function returns a percentile value (between 0.01 and 0.99) telling us the relative
|
|
7
|
+
// size of this vocabulary (the unique word count), based on the expected size of the vocabulary
|
|
8
|
+
// for a body of prose with the designated total word count. We start by creating three different
|
|
9
|
+
// parametric estimates (lo, mid, hi) representing the 10th percentile, 50th percentile, and 90th
|
|
10
|
+
// percentile. Then we use the actual unique word count to interpolate between these values. The
|
|
11
|
+
// coefficients in these formulae were generated by performing a power-law regression over 9570
|
|
12
|
+
// works of fiction, having various different lengths and vocabulary sizes, and then adjusting
|
|
13
|
+
// the values to satisfy the 10th, 50th, and 90th percentile counts. Finally, although this
|
|
14
|
+
// parametric model is more accurate in estimating actual vocabulary sizes, it's also handy
|
|
15
|
+
// to remember this convenient shorthand: "vocabulary size scales proportionally to the square
|
|
16
|
+
// root of the total word count".
|
|
17
|
+
let coefficient = 9.3676;
|
|
18
|
+
let loEstimate = coefficient * Math.pow(wordCount, 0.5701);
|
|
19
|
+
let midEstimate = coefficient * Math.pow(wordCount, 0.5884);
|
|
20
|
+
let hiEstimate = coefficient * Math.pow(wordCount, 0.6070);
|
|
21
|
+
if (uniqueCount < loEstimate - ((midEstimate - loEstimate) / 4)) {
|
|
22
|
+
return 0.01;
|
|
23
|
+
}
|
|
24
|
+
else if (uniqueCount > hiEstimate + ((hiEstimate - midEstimate) / 4)) {
|
|
25
|
+
return 0.99;
|
|
26
|
+
}
|
|
27
|
+
else if (uniqueCount < midEstimate) {
|
|
28
|
+
return 0.1 + (0.4 * (uniqueCount - loEstimate) / (midEstimate - loEstimate));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return 0.9 - (0.4 * (hiEstimate - uniqueCount) / (hiEstimate - midEstimate));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Vocabulary = Vocabulary;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './Async';
|
|
2
|
+
export * from './Base62';
|
|
3
|
+
export * from './BinarySearch';
|
|
4
|
+
export * from './CachingHasher';
|
|
5
|
+
export * from './Color';
|
|
6
|
+
export * from './Dispatch';
|
|
7
|
+
export * from './EditDistance';
|
|
8
|
+
export * from './Encryption';
|
|
9
|
+
export * from './NumberFormat';
|
|
10
|
+
export * from './Logging';
|
|
11
|
+
export * from './Struct';
|
|
12
|
+
export * from './Template';
|
|
13
|
+
export * from './Text';
|
|
14
|
+
export * from './Tuples';
|
|
15
|
+
export * from './Validate';
|
|
16
|
+
export * from './Vocabulary';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// created from 'create-ts-index'
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./Async"), exports);
|
|
19
|
+
__exportStar(require("./Base62"), exports);
|
|
20
|
+
__exportStar(require("./BinarySearch"), exports);
|
|
21
|
+
__exportStar(require("./CachingHasher"), exports);
|
|
22
|
+
__exportStar(require("./Color"), exports);
|
|
23
|
+
__exportStar(require("./Dispatch"), exports);
|
|
24
|
+
__exportStar(require("./EditDistance"), exports);
|
|
25
|
+
__exportStar(require("./Encryption"), exports);
|
|
26
|
+
__exportStar(require("./NumberFormat"), exports);
|
|
27
|
+
__exportStar(require("./Logging"), exports);
|
|
28
|
+
__exportStar(require("./Struct"), exports);
|
|
29
|
+
__exportStar(require("./Template"), exports);
|
|
30
|
+
__exportStar(require("./Text"), exports);
|
|
31
|
+
__exportStar(require("./Tuples"), exports);
|
|
32
|
+
__exportStar(require("./Validate"), exports);
|
|
33
|
+
__exportStar(require("./Vocabulary"), exports);
|