@shaxpir/duiduidui-models 1.0.1 → 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/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
- package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
- package/dist/models/BayesianScore.d.ts +9 -0
- package/dist/models/BayesianScore.js +27 -0
- package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
- package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
- package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
- package/dist/models/{content/Content.js → Content.js} +2 -6
- package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
- package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
- package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
- package/dist/models/{content/Device.js → Device.js} +14 -18
- package/dist/models/Hanzi.d.ts +15 -0
- package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
- package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
- package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
- package/dist/models/{content/Media.js → Media.js} +4 -5
- package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
- package/dist/models/{content/Metric.js → Metric.js} +18 -20
- package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
- package/dist/models/{content/Model.js → Model.js} +5 -6
- package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
- package/dist/models/{markup/Operation.js → Operation.js} +30 -25
- package/dist/models/Phrase.d.ts +39 -0
- package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
- package/dist/models/{content/Profile.js → Profile.js} +7 -9
- package/dist/models/Progress.d.ts +26 -0
- package/dist/models/Progress.js +39 -0
- package/dist/models/Review.d.ts +14 -0
- package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
- package/dist/models/Session.js +103 -0
- package/dist/models/Term.d.ts +36 -0
- package/dist/models/Term.js +82 -0
- package/dist/models/User.d.ts +32 -0
- package/dist/models/User.js +65 -0
- package/dist/models/Workspace.d.ts +37 -0
- package/dist/models/Workspace.js +94 -0
- package/dist/models/index.d.ts +22 -2
- package/dist/models/index.js +22 -2
- package/dist/repo/PermissiveJson1.d.ts +16 -16
- package/dist/repo/PermissiveJson1.js +17 -7
- package/dist/repo/ShareSync.d.ts +6 -6
- package/dist/repo/ShareSync.js +26 -19
- package/dist/repo/index.d.ts +1 -0
- package/dist/repo/index.js +1 -0
- package/dist/util/Encryption.d.ts +1 -1
- package/dist/util/index.d.ts +0 -6
- package/dist/util/index.js +0 -6
- package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
- package/lib/models/BayesianScore.ts +32 -0
- package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
- package/lib/models/{content/Content.ts → Content.ts} +15 -18
- package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
- package/lib/models/{content/Device.ts → Device.ts} +26 -22
- package/lib/models/Hanzi.ts +16 -0
- package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
- package/lib/models/{content/Media.ts → Media.ts} +3 -4
- package/lib/models/Metric.ts +233 -0
- package/lib/models/{content/Model.ts → Model.ts} +4 -6
- package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
- package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
- package/lib/models/Phrase.ts +53 -0
- package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
- package/lib/models/Progress.ts +66 -0
- package/lib/models/Review.ts +18 -0
- package/lib/models/Session.ts +140 -0
- package/lib/models/Term.ts +139 -0
- package/lib/models/User.ts +97 -0
- package/lib/models/Workspace.ts +129 -0
- package/lib/models/index.ts +22 -2
- package/lib/repo/ShareSync.ts +9 -13
- package/lib/repo/index.ts +1 -0
- package/lib/util/Encryption.ts +1 -1
- package/lib/util/index.ts +0 -6
- package/package.json +4 -15
- package/dist/models/OutboundMessage.d.ts +0 -18
- package/dist/models/OutboundMessage.js +0 -25
- package/dist/models/content/Activity.d.ts +0 -10
- package/dist/models/content/Billing.d.ts +0 -144
- package/dist/models/content/Billing.js +0 -418
- package/dist/models/content/Book.d.ts +0 -77
- package/dist/models/content/Book.js +0 -407
- package/dist/models/content/Category.d.ts +0 -16
- package/dist/models/content/Category.js +0 -20
- package/dist/models/content/Checkpointable.d.ts +0 -21
- package/dist/models/content/Checkpointable.js +0 -156
- package/dist/models/content/Comment.d.ts +0 -19
- package/dist/models/content/Comment.js +0 -53
- package/dist/models/content/ConceptArt.d.ts +0 -31
- package/dist/models/content/ConceptArt.js +0 -84
- package/dist/models/content/Context.d.ts +0 -28
- package/dist/models/content/Context.js +0 -162
- package/dist/models/content/DevEnv.d.ts +0 -5
- package/dist/models/content/DevEnv.js +0 -9
- package/dist/models/content/Dictionary.d.ts +0 -31
- package/dist/models/content/Dictionary.js +0 -5
- package/dist/models/content/DictionaryEntry.d.ts +0 -20
- package/dist/models/content/DictionaryEntry.js +0 -2
- package/dist/models/content/ElasticModel.d.ts +0 -149
- package/dist/models/content/ElasticModel.js +0 -179
- package/dist/models/content/Environment.d.ts +0 -61
- package/dist/models/content/Environment.js +0 -124
- package/dist/models/content/ExportOptions.d.ts +0 -64
- package/dist/models/content/ExportOptions.js +0 -213
- package/dist/models/content/Folder.d.ts +0 -16
- package/dist/models/content/Folder.js +0 -33
- package/dist/models/content/Fragment.d.ts +0 -54
- package/dist/models/content/Fragment.js +0 -181
- package/dist/models/content/Hanzi.d.ts +0 -21
- package/dist/models/content/HighlightRule.d.ts +0 -9
- package/dist/models/content/HighlightRule.js +0 -2
- package/dist/models/content/Migration.d.ts +0 -68
- package/dist/models/content/Migration.js +0 -155
- package/dist/models/content/Phrase.d.ts +0 -8
- package/dist/models/content/Placeholder.d.ts +0 -8
- package/dist/models/content/Placeholder.js +0 -36
- package/dist/models/content/RichText.d.ts +0 -58
- package/dist/models/content/RichText.js +0 -79
- package/dist/models/content/Session.js +0 -173
- package/dist/models/content/Speech.d.ts +0 -67
- package/dist/models/content/Speech.js +0 -97
- package/dist/models/content/Stub.d.ts +0 -24
- package/dist/models/content/Stub.js +0 -179
- package/dist/models/content/Time.d.ts +0 -56
- package/dist/models/content/Time.js +0 -295
- package/dist/models/content/User.d.ts +0 -36
- package/dist/models/content/User.js +0 -95
- package/dist/models/content/Workspace.d.ts +0 -71
- package/dist/models/content/Workspace.js +0 -237
- package/dist/models/content/index.d.ts +0 -17
- package/dist/models/content/index.js +0 -34
- package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
- package/dist/models/legacy/LegacyBodyFormat.js +0 -2
- package/dist/models/legacy/LegacyComment.d.ts +0 -12
- package/dist/models/legacy/LegacyComment.js +0 -2
- package/dist/models/legacy/LegacyContent.d.ts +0 -53
- package/dist/models/legacy/LegacyContent.js +0 -55
- package/dist/models/legacy/LegacyConversion.d.ts +0 -55
- package/dist/models/legacy/LegacyConversion.js +0 -401
- package/dist/models/legacy/LegacyFragment.d.ts +0 -21
- package/dist/models/legacy/LegacyFragment.js +0 -2
- package/dist/models/legacy/LegacyLocator.d.ts +0 -8
- package/dist/models/legacy/LegacyLocator.js +0 -31
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
- package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
- package/dist/models/legacy/LegacyPicture.d.ts +0 -14
- package/dist/models/legacy/LegacyPicture.js +0 -2
- package/dist/models/legacy/LegacyProfile.d.ts +0 -9
- package/dist/models/legacy/LegacyProfile.js +0 -2
- package/dist/models/legacy/LegacySession.d.ts +0 -41
- package/dist/models/legacy/LegacySession.js +0 -35
- package/dist/models/legacy/LegacyStory.d.ts +0 -23
- package/dist/models/legacy/LegacyStory.js +0 -2
- package/dist/models/legacy/LegacyStub.d.ts +0 -15
- package/dist/models/legacy/LegacyStub.js +0 -2
- package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
- package/dist/models/legacy/LegacyTransaction.js +0 -49
- package/dist/models/legacy/LegacyUser.d.ts +0 -28
- package/dist/models/legacy/LegacyUser.js +0 -32
- package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
- package/dist/models/legacy/LegacyWorkspace.js +0 -6
- package/dist/models/legacy/index.d.ts +0 -15
- package/dist/models/legacy/index.js +0 -32
- package/dist/models/markup/BodyFormat.d.ts +0 -14
- package/dist/models/markup/BodyFormat.js +0 -190
- package/dist/models/markup/DeltaOps.d.ts +0 -5
- package/dist/models/markup/DeltaOps.js +0 -74
- package/dist/models/markup/HtmlMarkup.d.ts +0 -4
- package/dist/models/markup/HtmlMarkup.js +0 -21
- package/dist/models/markup/index.d.ts +0 -4
- package/dist/models/markup/index.js +0 -21
- package/dist/util/Async.d.ts +0 -8
- package/dist/util/Async.js +0 -18
- package/dist/util/Base62.d.ts +0 -6
- package/dist/util/Base62.js +0 -47
- package/dist/util/BinarySearch.d.ts +0 -7
- package/dist/util/BinarySearch.js +0 -46
- package/dist/util/CachingHasher.d.ts +0 -8
- package/dist/util/CachingHasher.js +0 -41
- package/dist/util/Color.d.ts +0 -32
- package/dist/util/Color.js +0 -204
- package/dist/util/Dispatch.d.ts +0 -15
- package/dist/util/Dispatch.js +0 -79
- package/dist/util/EditDistance.d.ts +0 -13
- package/dist/util/EditDistance.js +0 -184
- package/dist/util/NumberFormat.d.ts +0 -14
- package/dist/util/NumberFormat.js +0 -224
- package/dist/util/Struct.d.ts +0 -4
- package/dist/util/Struct.js +0 -15
- package/dist/util/Template.d.ts +0 -16
- package/dist/util/Template.js +0 -128
- package/dist/util/Text.d.ts +0 -45
- package/dist/util/Text.js +0 -243
- package/dist/util/Tuples.d.ts +0 -9
- package/dist/util/Tuples.js +0 -135
- package/dist/util/Validate.d.ts +0 -4
- package/dist/util/Validate.js +0 -11
- package/dist/util/Vocabulary.d.ts +0 -3
- package/dist/util/Vocabulary.js +0 -35
- package/lib/models/content/Billing.ts +0 -558
- package/lib/models/content/DevEnv.ts +0 -5
- package/lib/models/content/DictionaryEntry.ts +0 -22
- package/lib/models/content/Hanzi.ts +0 -25
- package/lib/models/content/Phrase.ts +0 -10
- package/lib/models/content/Time.ts +0 -328
- package/lib/models/content/User.ts +0 -130
- package/lib/models/content/index.ts +0 -19
- package/lib/models/markup/DeltaOps.ts +0 -71
- package/lib/models/markup/index.ts +0 -6
- package/lib/util/Base62.ts +0 -47
- package/lib/util/CachingHasher.ts +0 -38
- package/lib/util/Dispatch.ts +0 -92
- package/lib/util/NumberFormat.ts +0 -194
- package/lib/util/Struct.ts +0 -14
- package/lib/util/Tuples.ts +0 -131
- /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
- /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
- /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
- /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
- /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
- /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
- /package/dist/models/{content/Activity.js → Review.js} +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
- /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
- /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpeechPersona = exports.SpeechAge = exports.SpeechGender = exports.SpeechDialect = exports.SpeechLanguage = exports.SpeechEngine = exports.SpeechProvider = exports.SpeechDataType = void 0;
|
|
4
|
-
var SpeechDataType;
|
|
5
|
-
(function (SpeechDataType) {
|
|
6
|
-
SpeechDataType["AUDIO_MP3"] = "audio_mp3";
|
|
7
|
-
SpeechDataType["AUDIO_OGG"] = "audio_ogg";
|
|
8
|
-
SpeechDataType["META_WORD_MARKS"] = "meta_word_marks";
|
|
9
|
-
})(SpeechDataType || (exports.SpeechDataType = SpeechDataType = {}));
|
|
10
|
-
var SpeechProvider;
|
|
11
|
-
(function (SpeechProvider) {
|
|
12
|
-
SpeechProvider["AWS"] = "aws";
|
|
13
|
-
SpeechProvider["ELEVEN_LABS"] = "eleven_labs";
|
|
14
|
-
})(SpeechProvider || (exports.SpeechProvider = SpeechProvider = {}));
|
|
15
|
-
var SpeechEngine;
|
|
16
|
-
(function (SpeechEngine) {
|
|
17
|
-
SpeechEngine["STANDARD"] = "standard";
|
|
18
|
-
SpeechEngine["NEURAL"] = "neural";
|
|
19
|
-
})(SpeechEngine || (exports.SpeechEngine = SpeechEngine = {}));
|
|
20
|
-
;
|
|
21
|
-
var SpeechLanguage;
|
|
22
|
-
(function (SpeechLanguage) {
|
|
23
|
-
SpeechLanguage["ENGLISH"] = "English";
|
|
24
|
-
})(SpeechLanguage || (exports.SpeechLanguage = SpeechLanguage = {}));
|
|
25
|
-
;
|
|
26
|
-
var SpeechDialect;
|
|
27
|
-
(function (SpeechDialect) {
|
|
28
|
-
SpeechDialect["US"] = "US";
|
|
29
|
-
SpeechDialect["AU"] = "AU";
|
|
30
|
-
SpeechDialect["GB"] = "GB";
|
|
31
|
-
SpeechDialect["IN"] = "IN";
|
|
32
|
-
})(SpeechDialect || (exports.SpeechDialect = SpeechDialect = {}));
|
|
33
|
-
var SpeechGender;
|
|
34
|
-
(function (SpeechGender) {
|
|
35
|
-
SpeechGender["MALE"] = "Male";
|
|
36
|
-
SpeechGender["FEMALE"] = "Female";
|
|
37
|
-
})(SpeechGender || (exports.SpeechGender = SpeechGender = {}));
|
|
38
|
-
var SpeechAge;
|
|
39
|
-
(function (SpeechAge) {
|
|
40
|
-
SpeechAge["ADULT"] = "Adult";
|
|
41
|
-
SpeechAge["CHILD"] = "Child";
|
|
42
|
-
SpeechAge["ELDERLY"] = "Elderly";
|
|
43
|
-
})(SpeechAge || (exports.SpeechAge = SpeechAge = {}));
|
|
44
|
-
class SpeechPersona {
|
|
45
|
-
constructor(code, name, provider, engine, language, dialect, gender, age) {
|
|
46
|
-
this.code = code;
|
|
47
|
-
this.name = name;
|
|
48
|
-
this.provider = provider;
|
|
49
|
-
this.engine = engine;
|
|
50
|
-
this.language = language;
|
|
51
|
-
this.dialect = dialect;
|
|
52
|
-
this.gender = gender;
|
|
53
|
-
this.age = age;
|
|
54
|
-
}
|
|
55
|
-
static byName(name) {
|
|
56
|
-
name = name.toLowerCase();
|
|
57
|
-
for (let i = 0; i < SpeechPersona.ALL.length; i++) {
|
|
58
|
-
const persona = SpeechPersona.ALL[i];
|
|
59
|
-
if (persona.name.toLowerCase() == name) {
|
|
60
|
-
return persona;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
getLangaugeCode() {
|
|
66
|
-
if (this.language === SpeechLanguage.ENGLISH) {
|
|
67
|
-
if (this.dialect === SpeechDialect.US) {
|
|
68
|
-
return "en-US";
|
|
69
|
-
}
|
|
70
|
-
else if (this.dialect === SpeechDialect.GB) {
|
|
71
|
-
return "en-GB";
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SpeechPersona = SpeechPersona;
|
|
78
|
-
SpeechPersona.AMY = new SpeechPersona("00", "Amy", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
79
|
-
SpeechPersona.BRIAN = new SpeechPersona("01", "Brian", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.MALE, SpeechAge.ADULT);
|
|
80
|
-
SpeechPersona.EMMA = new SpeechPersona("02", "Emma", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
81
|
-
SpeechPersona.IVY = new SpeechPersona("03", "Ivy", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.CHILD);
|
|
82
|
-
SpeechPersona.JOANNA = new SpeechPersona("04", "Joanna", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
83
|
-
SpeechPersona.JOEY = new SpeechPersona("05", "Joey", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
|
|
84
|
-
SpeechPersona.JUSTIN = new SpeechPersona("06", "Justin", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.CHILD);
|
|
85
|
-
SpeechPersona.KENDRA = new SpeechPersona("07", "Kendra", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
86
|
-
SpeechPersona.KEVIN = new SpeechPersona("08", "Kevin", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.CHILD);
|
|
87
|
-
SpeechPersona.KIMBERY = new SpeechPersona("09", "Kimberly", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
88
|
-
SpeechPersona.MATTHEW = new SpeechPersona("0a", "Matthew", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
|
|
89
|
-
SpeechPersona.SALLI = new SpeechPersona("0b", "Salli", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
90
|
-
SpeechPersona.DAVID = new SpeechPersona("5FlhwUeTKmBbKy4nphG3", "David", SpeechProvider.ELEVEN_LABS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
|
|
91
|
-
SpeechPersona.RACHEL = new SpeechPersona("nTeH5Tfb8NMpR0YHgOSI", "Rachel", SpeechProvider.ELEVEN_LABS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
|
|
92
|
-
SpeechPersona.DEFAULT = SpeechPersona.JOANNA;
|
|
93
|
-
SpeechPersona.ALL = [
|
|
94
|
-
SpeechPersona.AMY, SpeechPersona.BRIAN, SpeechPersona.EMMA, SpeechPersona.IVY, SpeechPersona.JOANNA, SpeechPersona.JOEY,
|
|
95
|
-
SpeechPersona.JUSTIN, SpeechPersona.KENDRA, SpeechPersona.KEVIN, SpeechPersona.KIMBERY, SpeechPersona.MATTHEW, SpeechPersona.SALLI,
|
|
96
|
-
SpeechPersona.DAVID, SpeechPersona.RACHEL
|
|
97
|
-
];
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ArrayView } from "./ArrayView";
|
|
2
|
-
import { ContentId, ContentRef } from "./Content";
|
|
3
|
-
import { ContentKind } from "./ContentKind";
|
|
4
|
-
export interface Stub {
|
|
5
|
-
kind: ContentKind;
|
|
6
|
-
label: string;
|
|
7
|
-
parent?: ContentId;
|
|
8
|
-
children?: Stub[];
|
|
9
|
-
}
|
|
10
|
-
export interface FolderStub extends Stub {
|
|
11
|
-
id: ContentId;
|
|
12
|
-
}
|
|
13
|
-
export interface ContentStub extends Stub {
|
|
14
|
-
category?: string;
|
|
15
|
-
ref: ContentRef;
|
|
16
|
-
}
|
|
17
|
-
export declare class Stubs {
|
|
18
|
-
static idFromStub(stub: Stub): ContentId;
|
|
19
|
-
static refFromStub(stub: Stub): ContentRef;
|
|
20
|
-
static unflatten(stubs: Stub[]): Stub[];
|
|
21
|
-
static isFolderStub(stub: Stub): boolean;
|
|
22
|
-
static isContentStub(stub: Stub): boolean;
|
|
23
|
-
static insertStubAtActivePoint(stub: Stub, stubArrayView: ArrayView<Stub>, category: string, activeId: ContentId, defaultAtBeginning: boolean): number;
|
|
24
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Stubs = void 0;
|
|
7
|
-
const pluralize_1 = __importDefault(require("pluralize"));
|
|
8
|
-
const Struct_1 = require("../../util/Struct");
|
|
9
|
-
const Content_1 = require("./Content");
|
|
10
|
-
const ContentKind_1 = require("./ContentKind");
|
|
11
|
-
class Stubs {
|
|
12
|
-
static idFromStub(stub) {
|
|
13
|
-
let id = null;
|
|
14
|
-
if (typeof (stub) === "string") {
|
|
15
|
-
// The array entry is a bare string... either a locator or an ID.
|
|
16
|
-
id = Content_1.Content.parseContentRef(stub).id;
|
|
17
|
-
}
|
|
18
|
-
else if (stub.hasOwnProperty("id")) {
|
|
19
|
-
id = stub.id;
|
|
20
|
-
}
|
|
21
|
-
else if (stub.hasOwnProperty("ref")) {
|
|
22
|
-
id = Content_1.Content.parseContentRef(stub.ref).id;
|
|
23
|
-
}
|
|
24
|
-
return id;
|
|
25
|
-
}
|
|
26
|
-
static refFromStub(stub) {
|
|
27
|
-
let ref = null;
|
|
28
|
-
if (typeof (stub) === "string") {
|
|
29
|
-
ref = stub;
|
|
30
|
-
}
|
|
31
|
-
else if (stub.hasOwnProperty("ref")) {
|
|
32
|
-
ref = stub.ref;
|
|
33
|
-
}
|
|
34
|
-
else if (stub.hasOwnProperty("id")) {
|
|
35
|
-
ref = stub.id;
|
|
36
|
-
}
|
|
37
|
-
return ref;
|
|
38
|
-
}
|
|
39
|
-
static unflatten(stubs) {
|
|
40
|
-
const nodesById = new Map();
|
|
41
|
-
const unflattened = [];
|
|
42
|
-
for (let i = 0, len = stubs.length; i < len; i++) {
|
|
43
|
-
const stub = Struct_1.Struct.clone(stubs[i]);
|
|
44
|
-
const id = Stubs.idFromStub(stub);
|
|
45
|
-
nodesById.set(id, stub);
|
|
46
|
-
if (stub.parent && nodesById.has(stub.parent)) {
|
|
47
|
-
const parentNode = nodesById.get(stub.parent);
|
|
48
|
-
if (!parentNode.hasOwnProperty("children")) {
|
|
49
|
-
parentNode.children = [];
|
|
50
|
-
}
|
|
51
|
-
parentNode.children.push(stub);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
unflattened.push(stub);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return unflattened;
|
|
58
|
-
}
|
|
59
|
-
static isFolderStub(stub) {
|
|
60
|
-
return stub && stub.hasOwnProperty('kind') && stub.kind == ContentKind_1.ContentKind.FOLDER;
|
|
61
|
-
}
|
|
62
|
-
static isContentStub(stub) {
|
|
63
|
-
return stub && stub.hasOwnProperty('ref');
|
|
64
|
-
}
|
|
65
|
-
// Given an array of fragment stubs (like you'd find in 'book.payload.manuscript',
|
|
66
|
-
// 'book.payload.notebook', or 'book.payload.ideas'), this function adds the
|
|
67
|
-
// designated stub to the array at the correct index. This is based in part on
|
|
68
|
-
// whether a fragment is already 'active' (selected by the user in the workspace
|
|
69
|
-
// tree) and whether the default insertion point is at the beginning or end of
|
|
70
|
-
// the array. When the correct insertion point has been found the function
|
|
71
|
-
// automatically injects the correct tree-parent ID into the stub.
|
|
72
|
-
static insertStubAtActivePoint(stub, stubArrayView, category, activeId, defaultAtBeginning) {
|
|
73
|
-
// Build a parentage map of all the stubs in the array.
|
|
74
|
-
const parentage = new Map();
|
|
75
|
-
const indexesById = new Map();
|
|
76
|
-
// Try to find a folder whose label matches the pluralization of the category for this stub.
|
|
77
|
-
// For example, if the stub has a category of "character", then a matching folder would be
|
|
78
|
-
// named "CHARACTERS" or "Characters". If we find such a folder, then the new stub will be
|
|
79
|
-
// added within the matching folder's hierarchy.
|
|
80
|
-
let categoryFolderStubIdx = -1;
|
|
81
|
-
if (category !== null) {
|
|
82
|
-
const singularCategory = pluralize_1.default.singular(category.toLowerCase());
|
|
83
|
-
for (let i = 0, len = stubArrayView.length; i < len; i++) {
|
|
84
|
-
const currentStub = stubArrayView.get(i);
|
|
85
|
-
const stubId = Stubs.idFromStub(currentStub);
|
|
86
|
-
indexesById.set(stubId, i);
|
|
87
|
-
if (currentStub.parent) {
|
|
88
|
-
parentage.set(stubId, currentStub.parent);
|
|
89
|
-
}
|
|
90
|
-
if (Stubs.isFolderStub(currentStub)) {
|
|
91
|
-
const folderLabel = currentStub.label.toLowerCase();
|
|
92
|
-
const singularLabel = pluralize_1.default.singular(folderLabel);
|
|
93
|
-
if (singularLabel === singularCategory) {
|
|
94
|
-
categoryFolderStubIdx = i;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// Find the active ID (i.e., whatever is currently selected in the menu) in the stub array
|
|
100
|
-
let activeIdx = stubArrayView.firstIndexWhere(stub => Stubs.idFromStub(stub) === activeId);
|
|
101
|
-
// If there isn't an active ID (because nothing is currently selected in the menu), or if
|
|
102
|
-
// the active ID doesn't seem to be within this particular stub array (manuscript vs notebook),
|
|
103
|
-
// then treat any category folder we might have found ("Characters" or "Themes", etc) as the
|
|
104
|
-
// as an active ID.
|
|
105
|
-
if (activeIdx === -1) {
|
|
106
|
-
activeIdx = categoryFolderStubIdx;
|
|
107
|
-
}
|
|
108
|
-
else if (categoryFolderStubIdx !== -1) {
|
|
109
|
-
// If the active stub and the category folder stub both exist, then we need to figure out
|
|
110
|
-
// which of them takes priority. Matching a category folder is more important, so generally,
|
|
111
|
-
// we will just use the category folder. But if the active index is WITHIN the category
|
|
112
|
-
// folder, then we'll use the active ID instead.
|
|
113
|
-
let activeIdIsWithinCategoryFolder = false;
|
|
114
|
-
let currentStub = stubArrayView.get(activeIdx);
|
|
115
|
-
while (currentStub) {
|
|
116
|
-
const currentStubId = Stubs.idFromStub(currentStub);
|
|
117
|
-
if (parentage.has(currentStubId)) {
|
|
118
|
-
const parentId = parentage.get(currentStubId);
|
|
119
|
-
if (indexesById.has(parentId)) {
|
|
120
|
-
const parentStubIndex = indexesById.get(parentId);
|
|
121
|
-
if (parentStubIndex === categoryFolderStubIdx) {
|
|
122
|
-
activeIdIsWithinCategoryFolder = true;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
currentStub = stubArrayView.get(parentStubIndex);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// NOTE: It should be impossible to get here, because we've already built a map of all the
|
|
129
|
-
// stubs in the array, and we've already checked that the parentage map contains the parent ID.
|
|
130
|
-
throw new Error(`Parent ID ${parentId} not found in stub array`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
currentStub = undefined;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (!activeIdIsWithinCategoryFolder) {
|
|
138
|
-
activeIdx = categoryFolderStubIdx;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// Insert the new stub into the array at the index of the active stub (which
|
|
142
|
-
// may have been adjusted above to point to the category folder index).
|
|
143
|
-
let idx;
|
|
144
|
-
if (activeIdx === -1) {
|
|
145
|
-
// Couldn't find the active ID in the array of stubs. Add the stub at either
|
|
146
|
-
// the beginning or end of the array, depending on the designated default.
|
|
147
|
-
if (defaultAtBeginning) {
|
|
148
|
-
stubArrayView.unshift(stub);
|
|
149
|
-
idx = 0;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
idx = stubArrayView.length;
|
|
153
|
-
stubArrayView.push(stub);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Find the stub at the active index. If it's a folder, then use it as the parent of the new stub. Otherwise,
|
|
158
|
-
// if the stub at the active index has a parent, then the new stub should assume the same parent as its sibling.
|
|
159
|
-
const activeStub = stubArrayView.get(activeIdx);
|
|
160
|
-
if (Stubs.isFolderStub(activeStub)) {
|
|
161
|
-
const folderStub = activeStub;
|
|
162
|
-
stub.parent = folderStub.id;
|
|
163
|
-
}
|
|
164
|
-
else if (activeStub.parent) {
|
|
165
|
-
stub.parent = activeStub.parent;
|
|
166
|
-
}
|
|
167
|
-
// Insert the new stub immediately after the active stub.
|
|
168
|
-
idx = activeIdx + 1;
|
|
169
|
-
if (idx >= stubArrayView.length) {
|
|
170
|
-
stubArrayView.push(stub);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
stubArrayView.insert(idx, stub);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return idx;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
exports.Stubs = Stubs;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
declare enum CompactDateTimeBrand {
|
|
3
|
-
}
|
|
4
|
-
declare enum CompactDateBrand {
|
|
5
|
-
}
|
|
6
|
-
export type CompactDateTime = string & CompactDateTimeBrand;
|
|
7
|
-
export type CompactDate = string & CompactDateBrand;
|
|
8
|
-
export interface SingleTime {
|
|
9
|
-
utc_time: CompactDateTime;
|
|
10
|
-
}
|
|
11
|
-
export interface MultiTime {
|
|
12
|
-
utc_time: CompactDateTime;
|
|
13
|
-
local_time: CompactDateTime;
|
|
14
|
-
}
|
|
15
|
-
export declare class MultiClock {
|
|
16
|
-
static utcNow(): MultiTime;
|
|
17
|
-
static now(): MultiTime;
|
|
18
|
-
}
|
|
19
|
-
export declare class Time {
|
|
20
|
-
static readonly DATETIME_FORMAT_LEGACY: string;
|
|
21
|
-
static readonly DATE_FORMAT: string;
|
|
22
|
-
static readonly DATETIME_FORMAT_COMPACT: string;
|
|
23
|
-
static readonly DATE_NO_YEAR: string;
|
|
24
|
-
static readonly DATE_BEAUTIFIED: string;
|
|
25
|
-
static readonly DATE_FULLY_BEAUTIFIED: string;
|
|
26
|
-
static readonly YEAR_ONLY: string;
|
|
27
|
-
static asCompactDateTime(text: string): CompactDateTime;
|
|
28
|
-
static asCompactDate(text: string): CompactDate | null;
|
|
29
|
-
static isDateBefore(a: CompactDate, b: CompactDate): boolean;
|
|
30
|
-
static isDateAfter(a: CompactDate, b: CompactDate): boolean;
|
|
31
|
-
static compareDate(a: CompactDate, b: CompactDate): number;
|
|
32
|
-
static isDateTimeBefore(a: CompactDateTime, b: CompactDateTime): boolean;
|
|
33
|
-
static isDateTimeAfter(a: CompactDateTime, b: CompactDateTime): boolean;
|
|
34
|
-
static compareDateTime(a: CompactDateTime, b: CompactDateTime): number;
|
|
35
|
-
static sortByUtcTime(array: MultiTime[]): MultiTime[];
|
|
36
|
-
static dateFrom(timestamp: CompactDateTime): CompactDate;
|
|
37
|
-
static datesBetween(minDate: CompactDate, maxDate: CompactDate): CompactDate[];
|
|
38
|
-
static plus(timestamp: CompactDateTime, amount: number, units: dayjs.ManipulateType): CompactDateTime;
|
|
39
|
-
static todayLocal(): CompactDate;
|
|
40
|
-
static todayUtc(): CompactDate;
|
|
41
|
-
static startOfMonth(date: CompactDate): CompactDate;
|
|
42
|
-
static local(utc?: CompactDateTime): CompactDateTime;
|
|
43
|
-
static utcFromEpochSeconds(seconds: number): CompactDateTime;
|
|
44
|
-
static utc(local?: CompactDateTime): CompactDateTime;
|
|
45
|
-
static format(timestamp: CompactDateTime, pattern: string, isLocal: boolean): CompactDateTime;
|
|
46
|
-
static formatFromDate(date: Date, pattern: string): string;
|
|
47
|
-
static beautify(timestamp: CompactDateTime, isLocal?: boolean, amount?: number, units?: string): string;
|
|
48
|
-
static absDiffMinutes(a: CompactDateTime, b: CompactDateTime): number;
|
|
49
|
-
static elapsed(timestamp: CompactDateTime, isLocal: boolean): string;
|
|
50
|
-
static timeUntil(utcTime: CompactDateTime, units: dayjs.UnitType): number;
|
|
51
|
-
static timeSince(utcTime: CompactDateTime, units: dayjs.UnitType): number;
|
|
52
|
-
static currentYear(): string;
|
|
53
|
-
static humanizedDatePacific(epochSeconds: number): string;
|
|
54
|
-
static humanizedTimePacific(epochSeconds: number): string;
|
|
55
|
-
}
|
|
56
|
-
export {};
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Time = exports.MultiClock = void 0;
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
|
-
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
10
|
-
const dayOfYear_1 = __importDefault(require("dayjs/plugin/dayOfYear"));
|
|
11
|
-
dayjs_1.default.extend(utc_1.default);
|
|
12
|
-
dayjs_1.default.extend(timezone_1.default);
|
|
13
|
-
dayjs_1.default.extend(dayOfYear_1.default);
|
|
14
|
-
var CompactDateTimeBrand;
|
|
15
|
-
(function (CompactDateTimeBrand) {
|
|
16
|
-
})(CompactDateTimeBrand || (CompactDateTimeBrand = {}));
|
|
17
|
-
var CompactDateBrand;
|
|
18
|
-
(function (CompactDateBrand) {
|
|
19
|
-
})(CompactDateBrand || (CompactDateBrand = {}));
|
|
20
|
-
class MultiClock {
|
|
21
|
-
static utcNow() {
|
|
22
|
-
const localtime = Time.local();
|
|
23
|
-
const utcTime = Time.utc(localtime);
|
|
24
|
-
return {
|
|
25
|
-
local_time: utcTime,
|
|
26
|
-
utc_time: utcTime
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
static now() {
|
|
30
|
-
const localtime = Time.local();
|
|
31
|
-
return {
|
|
32
|
-
local_time: localtime,
|
|
33
|
-
utc_time: Time.utc(localtime)
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.MultiClock = MultiClock;
|
|
38
|
-
class Time {
|
|
39
|
-
static asCompactDateTime(text) {
|
|
40
|
-
// A compact datetime is always 17 digits long and starts with '20'
|
|
41
|
-
if (text.startsWith("20") && /^\d{17}$/.test(text)) {
|
|
42
|
-
return text;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
static asCompactDate(text) {
|
|
47
|
-
// A compact date is always 8 digits long and starts with '20'
|
|
48
|
-
if (text.startsWith("20") && /^\d{8}$/.test(text)) {
|
|
49
|
-
return text;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
static isDateBefore(a, b) {
|
|
54
|
-
return Time.compareDate(a, b) < 0;
|
|
55
|
-
}
|
|
56
|
-
static isDateAfter(a, b) {
|
|
57
|
-
return Time.compareDate(a, b) > 0;
|
|
58
|
-
}
|
|
59
|
-
static compareDate(a, b) {
|
|
60
|
-
if (a == null && b == null) {
|
|
61
|
-
return 0;
|
|
62
|
-
}
|
|
63
|
-
else if (a == null) {
|
|
64
|
-
return -1;
|
|
65
|
-
}
|
|
66
|
-
else if (b == null) {
|
|
67
|
-
return 1;
|
|
68
|
-
}
|
|
69
|
-
return a.localeCompare(b);
|
|
70
|
-
}
|
|
71
|
-
static isDateTimeBefore(a, b) {
|
|
72
|
-
return Time.compareDateTime(a, b) < 0;
|
|
73
|
-
}
|
|
74
|
-
static isDateTimeAfter(a, b) {
|
|
75
|
-
return Time.compareDateTime(a, b) > 0;
|
|
76
|
-
}
|
|
77
|
-
static compareDateTime(a, b) {
|
|
78
|
-
if (a == null && b == null) {
|
|
79
|
-
return 0;
|
|
80
|
-
}
|
|
81
|
-
else if (a == null) {
|
|
82
|
-
return -1;
|
|
83
|
-
}
|
|
84
|
-
else if (b == null) {
|
|
85
|
-
return 1;
|
|
86
|
-
}
|
|
87
|
-
return a.localeCompare(b);
|
|
88
|
-
}
|
|
89
|
-
static sortByUtcTime(array) {
|
|
90
|
-
return array.sort((a, b) => Time.compareDateTime(a.utc_time, b.utc_time));
|
|
91
|
-
}
|
|
92
|
-
static dateFrom(timestamp) {
|
|
93
|
-
const timestampText = timestamp;
|
|
94
|
-
if (timestampText.length >= 8 && /^\d{8}.*/.test(timestampText)) {
|
|
95
|
-
return timestampText.substring(0, 8);
|
|
96
|
-
}
|
|
97
|
-
if (typeof (timestamp) === "string") {
|
|
98
|
-
throw new Error("can\x27t parse date from malformed timestamp: " + timestamp);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error("can\x27t parse date from malformed timestamp: " + JSON.stringify(timestamp));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
static datesBetween(minDate, maxDate) {
|
|
105
|
-
const dates = new Array();
|
|
106
|
-
let d = minDate;
|
|
107
|
-
while (d.localeCompare(minDate) >= 0 && d.localeCompare(maxDate) <= 0) {
|
|
108
|
-
dates.push(d);
|
|
109
|
-
d = (0, dayjs_1.default)(d, Time.DATE_FORMAT).add(1, 'days').format(Time.DATE_FORMAT);
|
|
110
|
-
}
|
|
111
|
-
return dates;
|
|
112
|
-
}
|
|
113
|
-
static plus(timestamp, amount, units) {
|
|
114
|
-
const time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
|
|
115
|
-
return time.add(amount, units).format(Time.DATETIME_FORMAT_COMPACT);
|
|
116
|
-
}
|
|
117
|
-
static todayLocal() {
|
|
118
|
-
return Time.dateFrom(Time.local());
|
|
119
|
-
}
|
|
120
|
-
static todayUtc() {
|
|
121
|
-
return Time.dateFrom(Time.utc());
|
|
122
|
-
}
|
|
123
|
-
static startOfMonth(date) {
|
|
124
|
-
let text = date;
|
|
125
|
-
if (text.startsWith("20") && /^\d{8}$/.test(text)) {
|
|
126
|
-
text = text.substring(0, 6) + "01;";
|
|
127
|
-
}
|
|
128
|
-
return text;
|
|
129
|
-
}
|
|
130
|
-
static local(utc) {
|
|
131
|
-
let result;
|
|
132
|
-
if (typeof (utc) === "undefined") {
|
|
133
|
-
result = (0, dayjs_1.default)().format(Time.DATETIME_FORMAT_COMPACT);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
const timestamp = dayjs_1.default.utc(utc, Time.DATETIME_FORMAT_COMPACT)
|
|
137
|
-
.local();
|
|
138
|
-
result = timestamp.format(Time.DATETIME_FORMAT_COMPACT);
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
// TODO: Should this actually be called localFromEpochSeconds? Passing zero
|
|
143
|
-
// returns timestamp that is local-timezone hours offset from UTC epoch time.
|
|
144
|
-
static utcFromEpochSeconds(seconds) {
|
|
145
|
-
return dayjs_1.default.unix(seconds).utc().format(Time.DATETIME_FORMAT_COMPACT);
|
|
146
|
-
}
|
|
147
|
-
static utc(local) {
|
|
148
|
-
let result;
|
|
149
|
-
if (typeof (local) === "undefined") {
|
|
150
|
-
result = dayjs_1.default.utc().format(Time.DATETIME_FORMAT_COMPACT);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
const timestamp = (0, dayjs_1.default)(local, Time.DATETIME_FORMAT_COMPACT)
|
|
154
|
-
.utc();
|
|
155
|
-
result = timestamp.format(Time.DATETIME_FORMAT_COMPACT);
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
static format(timestamp, pattern, isLocal) {
|
|
160
|
-
let time = null;
|
|
161
|
-
if (isLocal) {
|
|
162
|
-
time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
|
|
166
|
-
.local();
|
|
167
|
-
}
|
|
168
|
-
return time.format(pattern);
|
|
169
|
-
}
|
|
170
|
-
static formatFromDate(date, pattern) {
|
|
171
|
-
const time = (0, dayjs_1.default)(date);
|
|
172
|
-
return time.format(pattern);
|
|
173
|
-
}
|
|
174
|
-
static beautify(timestamp, isLocal = false, amount, units) {
|
|
175
|
-
const now = (0, dayjs_1.default)();
|
|
176
|
-
let time = null;
|
|
177
|
-
if (isLocal) {
|
|
178
|
-
time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
|
|
182
|
-
.local();
|
|
183
|
-
}
|
|
184
|
-
// If the 'num' and 'units' params exist, then use them to manipulate the timestamp
|
|
185
|
-
if (typeof (amount) === "number" && typeof (units) === "string") {
|
|
186
|
-
time = time.add(amount, units);
|
|
187
|
-
}
|
|
188
|
-
let datePart = "", timePart = "";
|
|
189
|
-
const timeDayOfYear = time.dayOfYear();
|
|
190
|
-
const nowDayOfYear = now.dayOfYear();
|
|
191
|
-
const timeYear = time.year();
|
|
192
|
-
const nowYear = now.year();
|
|
193
|
-
if (nowDayOfYear === timeDayOfYear && nowYear === timeYear) {
|
|
194
|
-
datePart = "Today";
|
|
195
|
-
}
|
|
196
|
-
else if (nowDayOfYear - timeDayOfYear === 1 && nowYear === timeYear) {
|
|
197
|
-
datePart = "Yesterday";
|
|
198
|
-
}
|
|
199
|
-
else if (nowDayOfYear === 1 && timeDayOfYear === 365 && timeYear % 4 !== 0 && nowYear - timeYear === 1) {
|
|
200
|
-
datePart = "Yesterday";
|
|
201
|
-
}
|
|
202
|
-
else if (nowDayOfYear === 1 && timeDayOfYear === 366 && timeYear % 4 === 0 && nowYear - timeYear === 1) {
|
|
203
|
-
datePart = "Yesterday";
|
|
204
|
-
}
|
|
205
|
-
else if (timeDayOfYear - nowDayOfYear === 1 && timeYear === nowYear) {
|
|
206
|
-
datePart = "Tomorrow";
|
|
207
|
-
}
|
|
208
|
-
else if (timeDayOfYear === 1 && nowDayOfYear === 365 && nowYear % 4 !== 0 && timeYear - nowYear === 1) {
|
|
209
|
-
datePart = "Tomorrow";
|
|
210
|
-
}
|
|
211
|
-
else if (timeDayOfYear === 1 && nowDayOfYear === 366 && nowYear % 4 === 0 && timeYear - nowYear === 1) {
|
|
212
|
-
datePart = "Tomorrow";
|
|
213
|
-
}
|
|
214
|
-
else if (Math.abs(now.diff(time, "days")) <= 30) {
|
|
215
|
-
datePart = time.format(Time.DATE_FULLY_BEAUTIFIED);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
datePart = time.format(Time.DATE_BEAUTIFIED);
|
|
219
|
-
}
|
|
220
|
-
if (Math.abs(now.diff(time, "days")) <= 7) {
|
|
221
|
-
timePart = time.format("h:mm a");
|
|
222
|
-
timePart = timePart.replace(" am", "a");
|
|
223
|
-
timePart = timePart.replace(" pm", "p");
|
|
224
|
-
}
|
|
225
|
-
if (timePart.length === 0) {
|
|
226
|
-
return datePart;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
return datePart + ", " + timePart;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
static absDiffMinutes(a, b) {
|
|
233
|
-
const aMoment = (0, dayjs_1.default)(a, Time.DATETIME_FORMAT_COMPACT);
|
|
234
|
-
const bMoment = (0, dayjs_1.default)(b, Time.DATETIME_FORMAT_COMPACT);
|
|
235
|
-
return Math.abs(aMoment.diff(bMoment, 'minutes', true));
|
|
236
|
-
}
|
|
237
|
-
static elapsed(timestamp, isLocal) {
|
|
238
|
-
let time = null;
|
|
239
|
-
if (isLocal) {
|
|
240
|
-
time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
|
|
244
|
-
.local();
|
|
245
|
-
}
|
|
246
|
-
const difference = (0, dayjs_1.default)().diff(time, 'seconds');
|
|
247
|
-
if (difference < 60) {
|
|
248
|
-
return difference === 1 ? "1 second ago" : difference + " seconds ago";
|
|
249
|
-
}
|
|
250
|
-
else if (difference < 3 * 60) {
|
|
251
|
-
const minutes = Math.floor(difference / 60);
|
|
252
|
-
const seconds = Math.floor(difference % 60);
|
|
253
|
-
const minText = minutes === 1 ? "1 minute" : minutes + " minutes";
|
|
254
|
-
const secText = seconds === 1 ? "1 second" : seconds + " seconds";
|
|
255
|
-
return minText + ", " + secText + " ago";
|
|
256
|
-
}
|
|
257
|
-
else if (difference < 60 * 60) {
|
|
258
|
-
const minutes = Math.round(difference / 60);
|
|
259
|
-
return "about " + minutes + " minutes ago";
|
|
260
|
-
}
|
|
261
|
-
else if (difference < 24 * 60 * 60) {
|
|
262
|
-
const hours = Math.round(difference / (60 * 60));
|
|
263
|
-
return "about " + hours + " hours ago";
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
return Time.beautify(timestamp, isLocal);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
static timeUntil(utcTime, units) {
|
|
270
|
-
return -Time.timeSince(utcTime, units);
|
|
271
|
-
}
|
|
272
|
-
static timeSince(utcTime, units) {
|
|
273
|
-
const then = dayjs_1.default.utc(utcTime, Time.DATETIME_FORMAT_COMPACT);
|
|
274
|
-
const now = (0, dayjs_1.default)().utc();
|
|
275
|
-
return now.diff(then, units, true);
|
|
276
|
-
}
|
|
277
|
-
static currentYear() {
|
|
278
|
-
return (0, dayjs_1.default)().format(Time.YEAR_ONLY);
|
|
279
|
-
}
|
|
280
|
-
static humanizedDatePacific(epochSeconds) {
|
|
281
|
-
return dayjs_1.default.unix(epochSeconds).tz("America/Los_Angeles").format("MMMM D, YYYY");
|
|
282
|
-
}
|
|
283
|
-
// TODO: Should this actually expect seconds instead of milliseconds?
|
|
284
|
-
static humanizedTimePacific(epochSeconds) {
|
|
285
|
-
return (0, dayjs_1.default)(epochSeconds).tz("America/Los_Angeles").format("h:mm:ss a") + " (Pacific)";
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
exports.Time = Time;
|
|
289
|
-
Time.DATETIME_FORMAT_LEGACY = "YYYY-MM-DDTHH:mm:ss.SSSZ";
|
|
290
|
-
Time.DATE_FORMAT = "YYYYMMDD";
|
|
291
|
-
Time.DATETIME_FORMAT_COMPACT = "YYYYMMDDHHmmssSSS";
|
|
292
|
-
Time.DATE_NO_YEAR = "MMMM D";
|
|
293
|
-
Time.DATE_BEAUTIFIED = "MMMM D, YYYY";
|
|
294
|
-
Time.DATE_FULLY_BEAUTIFIED = "dddd, MMMM D, YYYY";
|
|
295
|
-
Time.YEAR_ONLY = "YYYY";
|