@shaxpir/duiduidui-models 1.0.0 → 1.1.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.
Files changed (223) hide show
  1. package/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
  2. package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
  3. package/dist/models/BayesianScore.d.ts +9 -0
  4. package/dist/models/BayesianScore.js +27 -0
  5. package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
  6. package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
  7. package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
  8. package/dist/models/{content/Content.js → Content.js} +2 -6
  9. package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
  10. package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
  11. package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
  12. package/dist/models/{content/Device.js → Device.js} +14 -18
  13. package/dist/models/Hanzi.d.ts +15 -0
  14. package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
  15. package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
  16. package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
  17. package/dist/models/{content/Media.js → Media.js} +4 -5
  18. package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
  19. package/dist/models/{content/Metric.js → Metric.js} +18 -20
  20. package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
  21. package/dist/models/{content/Model.js → Model.js} +5 -6
  22. package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
  23. package/dist/models/{markup/Operation.js → Operation.js} +30 -25
  24. package/dist/models/Phrase.d.ts +39 -0
  25. package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
  26. package/dist/models/{content/Profile.js → Profile.js} +7 -9
  27. package/dist/models/Progress.d.ts +26 -0
  28. package/dist/models/Progress.js +39 -0
  29. package/dist/models/Review.d.ts +14 -0
  30. package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
  31. package/dist/models/Session.js +103 -0
  32. package/dist/models/Term.d.ts +36 -0
  33. package/dist/models/Term.js +82 -0
  34. package/dist/models/User.d.ts +32 -0
  35. package/dist/models/User.js +65 -0
  36. package/dist/models/Workspace.d.ts +37 -0
  37. package/dist/models/Workspace.js +94 -0
  38. package/dist/models/index.d.ts +22 -4
  39. package/dist/models/index.js +22 -4
  40. package/dist/repo/PermissiveJson1.d.ts +16 -16
  41. package/dist/repo/PermissiveJson1.js +17 -7
  42. package/dist/repo/ShareSync.d.ts +6 -6
  43. package/dist/repo/ShareSync.js +26 -19
  44. package/dist/repo/index.d.ts +1 -0
  45. package/dist/repo/index.js +1 -0
  46. package/dist/util/index.d.ts +0 -14
  47. package/dist/util/index.js +0 -14
  48. package/lib/index.ts +5 -0
  49. package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
  50. package/lib/models/BayesianScore.ts +32 -0
  51. package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
  52. package/lib/models/{content/Content.ts → Content.ts} +15 -18
  53. package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
  54. package/lib/models/{content/Device.ts → Device.ts} +26 -22
  55. package/lib/models/Hanzi.ts +16 -0
  56. package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
  57. package/lib/models/{content/Media.ts → Media.ts} +3 -4
  58. package/lib/models/Metric.ts +233 -0
  59. package/lib/models/{content/Model.ts → Model.ts} +4 -6
  60. package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
  61. package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
  62. package/lib/models/Phrase.ts +53 -0
  63. package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
  64. package/lib/models/Progress.ts +66 -0
  65. package/lib/models/Review.ts +18 -0
  66. package/lib/models/Session.ts +140 -0
  67. package/lib/models/Term.ts +139 -0
  68. package/lib/models/User.ts +97 -0
  69. package/lib/models/Workspace.ts +129 -0
  70. package/lib/models/index.ts +24 -0
  71. package/lib/repo/ShareSync.ts +9 -13
  72. package/lib/repo/index.ts +6 -0
  73. package/lib/util/index.ts +4 -0
  74. package/package.json +4 -15
  75. package/dist/models/OutboundMessage.d.ts +0 -18
  76. package/dist/models/OutboundMessage.js +0 -25
  77. package/dist/models/content/Activity.d.ts +0 -10
  78. package/dist/models/content/Billing.d.ts +0 -144
  79. package/dist/models/content/Billing.js +0 -418
  80. package/dist/models/content/Book.d.ts +0 -77
  81. package/dist/models/content/Book.js +0 -407
  82. package/dist/models/content/Category.d.ts +0 -16
  83. package/dist/models/content/Category.js +0 -20
  84. package/dist/models/content/Checkpointable.d.ts +0 -21
  85. package/dist/models/content/Checkpointable.js +0 -156
  86. package/dist/models/content/Comment.d.ts +0 -19
  87. package/dist/models/content/Comment.js +0 -53
  88. package/dist/models/content/ConceptArt.d.ts +0 -31
  89. package/dist/models/content/ConceptArt.js +0 -84
  90. package/dist/models/content/Context.d.ts +0 -28
  91. package/dist/models/content/Context.js +0 -162
  92. package/dist/models/content/DevEnv.d.ts +0 -5
  93. package/dist/models/content/DevEnv.js +0 -9
  94. package/dist/models/content/Dictionary.d.ts +0 -31
  95. package/dist/models/content/Dictionary.js +0 -5
  96. package/dist/models/content/DictionaryEntry.d.ts +0 -20
  97. package/dist/models/content/DictionaryEntry.js +0 -2
  98. package/dist/models/content/ElasticModel.d.ts +0 -149
  99. package/dist/models/content/ElasticModel.js +0 -179
  100. package/dist/models/content/Environment.d.ts +0 -61
  101. package/dist/models/content/Environment.js +0 -124
  102. package/dist/models/content/ExportOptions.d.ts +0 -64
  103. package/dist/models/content/ExportOptions.js +0 -213
  104. package/dist/models/content/Folder.d.ts +0 -16
  105. package/dist/models/content/Folder.js +0 -33
  106. package/dist/models/content/Fragment.d.ts +0 -54
  107. package/dist/models/content/Fragment.js +0 -181
  108. package/dist/models/content/Hanzi.d.ts +0 -21
  109. package/dist/models/content/HighlightRule.d.ts +0 -9
  110. package/dist/models/content/HighlightRule.js +0 -2
  111. package/dist/models/content/Migration.d.ts +0 -68
  112. package/dist/models/content/Migration.js +0 -155
  113. package/dist/models/content/Phrase.d.ts +0 -8
  114. package/dist/models/content/Placeholder.d.ts +0 -8
  115. package/dist/models/content/Placeholder.js +0 -36
  116. package/dist/models/content/RichText.d.ts +0 -58
  117. package/dist/models/content/RichText.js +0 -79
  118. package/dist/models/content/Session.js +0 -173
  119. package/dist/models/content/Speech.d.ts +0 -67
  120. package/dist/models/content/Speech.js +0 -97
  121. package/dist/models/content/Stub.d.ts +0 -24
  122. package/dist/models/content/Stub.js +0 -179
  123. package/dist/models/content/Time.d.ts +0 -56
  124. package/dist/models/content/Time.js +0 -295
  125. package/dist/models/content/User.d.ts +0 -36
  126. package/dist/models/content/User.js +0 -95
  127. package/dist/models/content/Workspace.d.ts +0 -71
  128. package/dist/models/content/Workspace.js +0 -237
  129. package/dist/models/content/index.d.ts +0 -36
  130. package/dist/models/content/index.js +0 -53
  131. package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
  132. package/dist/models/legacy/LegacyBodyFormat.js +0 -2
  133. package/dist/models/legacy/LegacyComment.d.ts +0 -12
  134. package/dist/models/legacy/LegacyComment.js +0 -2
  135. package/dist/models/legacy/LegacyContent.d.ts +0 -53
  136. package/dist/models/legacy/LegacyContent.js +0 -55
  137. package/dist/models/legacy/LegacyConversion.d.ts +0 -55
  138. package/dist/models/legacy/LegacyConversion.js +0 -401
  139. package/dist/models/legacy/LegacyFragment.d.ts +0 -21
  140. package/dist/models/legacy/LegacyFragment.js +0 -2
  141. package/dist/models/legacy/LegacyLocator.d.ts +0 -8
  142. package/dist/models/legacy/LegacyLocator.js +0 -31
  143. package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
  144. package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
  145. package/dist/models/legacy/LegacyPicture.d.ts +0 -14
  146. package/dist/models/legacy/LegacyPicture.js +0 -2
  147. package/dist/models/legacy/LegacyProfile.d.ts +0 -9
  148. package/dist/models/legacy/LegacyProfile.js +0 -2
  149. package/dist/models/legacy/LegacySession.d.ts +0 -41
  150. package/dist/models/legacy/LegacySession.js +0 -35
  151. package/dist/models/legacy/LegacyStory.d.ts +0 -23
  152. package/dist/models/legacy/LegacyStory.js +0 -2
  153. package/dist/models/legacy/LegacyStub.d.ts +0 -15
  154. package/dist/models/legacy/LegacyStub.js +0 -2
  155. package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
  156. package/dist/models/legacy/LegacyTransaction.js +0 -49
  157. package/dist/models/legacy/LegacyUser.d.ts +0 -28
  158. package/dist/models/legacy/LegacyUser.js +0 -32
  159. package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
  160. package/dist/models/legacy/LegacyWorkspace.js +0 -6
  161. package/dist/models/legacy/index.d.ts +0 -15
  162. package/dist/models/legacy/index.js +0 -32
  163. package/dist/models/markup/BodyFormat.d.ts +0 -14
  164. package/dist/models/markup/BodyFormat.js +0 -190
  165. package/dist/models/markup/DeltaOps.d.ts +0 -5
  166. package/dist/models/markup/DeltaOps.js +0 -74
  167. package/dist/models/markup/HtmlMarkup.d.ts +0 -4
  168. package/dist/models/markup/HtmlMarkup.js +0 -21
  169. package/dist/models/markup/index.d.ts +0 -6
  170. package/dist/models/markup/index.js +0 -23
  171. package/dist/util/Async.d.ts +0 -8
  172. package/dist/util/Async.js +0 -18
  173. package/dist/util/Base62.d.ts +0 -6
  174. package/dist/util/Base62.js +0 -47
  175. package/dist/util/BinarySearch.d.ts +0 -7
  176. package/dist/util/BinarySearch.js +0 -46
  177. package/dist/util/CachingHasher.d.ts +0 -8
  178. package/dist/util/CachingHasher.js +0 -41
  179. package/dist/util/Color.d.ts +0 -32
  180. package/dist/util/Color.js +0 -204
  181. package/dist/util/Dispatch.d.ts +0 -15
  182. package/dist/util/Dispatch.js +0 -79
  183. package/dist/util/EditDistance.d.ts +0 -13
  184. package/dist/util/EditDistance.js +0 -184
  185. package/dist/util/NumberFormat.d.ts +0 -14
  186. package/dist/util/NumberFormat.js +0 -224
  187. package/dist/util/Struct.d.ts +0 -4
  188. package/dist/util/Struct.js +0 -15
  189. package/dist/util/Template.d.ts +0 -16
  190. package/dist/util/Template.js +0 -128
  191. package/dist/util/Text.d.ts +0 -45
  192. package/dist/util/Text.js +0 -243
  193. package/dist/util/Tuples.d.ts +0 -9
  194. package/dist/util/Tuples.js +0 -135
  195. package/dist/util/Validate.d.ts +0 -4
  196. package/dist/util/Validate.js +0 -11
  197. package/dist/util/Vocabulary.d.ts +0 -3
  198. package/dist/util/Vocabulary.js +0 -35
  199. package/lib/models/content/Billing.ts +0 -558
  200. package/lib/models/content/DevEnv.ts +0 -5
  201. package/lib/models/content/DictionaryEntry.ts +0 -22
  202. package/lib/models/content/Hanzi.ts +0 -25
  203. package/lib/models/content/Phrase.ts +0 -10
  204. package/lib/models/content/Time.ts +0 -328
  205. package/lib/models/content/User.ts +0 -130
  206. package/lib/models/markup/DeltaOps.ts +0 -71
  207. package/lib/util/Base62.ts +0 -47
  208. package/lib/util/CachingHasher.ts +0 -38
  209. package/lib/util/Dispatch.ts +0 -92
  210. package/lib/util/NumberFormat.ts +0 -194
  211. package/lib/util/Struct.ts +0 -14
  212. package/lib/util/Tuples.ts +0 -131
  213. /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
  214. /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
  215. /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
  216. /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
  217. /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
  218. /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
  219. /package/dist/models/{content/Activity.js → Review.js} +0 -0
  220. /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
  221. /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
  222. /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
  223. /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
@@ -1,92 +0,0 @@
1
- export type DispatchTopic = string;
2
- export type DispatchCallback = (topic:string, details?:any) => void;
3
-
4
- export interface DispatchMessage {
5
- topic:DispatchTopic;
6
- details?:any;
7
- }
8
-
9
- export class Dispatch {
10
-
11
- private static debug:boolean = false;
12
-
13
- private static readonly callbacksByTopic:Map<DispatchTopic, DispatchCallback[]> = new Map();
14
-
15
- public static setDebug(value:boolean):void {
16
- Dispatch.debug = value;
17
- }
18
-
19
- public static subscribe(
20
- topic:string,
21
- callback:DispatchCallback
22
- ):void {
23
- let topicCallbacks:DispatchCallback[] = [];
24
- if (Dispatch.callbacksByTopic.has(topic)) {
25
- topicCallbacks = Dispatch.callbacksByTopic.get(topic);
26
- } else {
27
- Dispatch.callbacksByTopic.set(topic, topicCallbacks);
28
- }
29
- topicCallbacks.push(callback);
30
- }
31
-
32
- public static unsubscribe(
33
- topic:DispatchTopic,
34
- callback:DispatchCallback
35
- ) {
36
- if (Dispatch.callbacksByTopic.has(topic)) {
37
- let topicCallbacks:DispatchCallback[] = [];
38
- let newTopicCallbacks = [];
39
- for (let i = 0, len = topicCallbacks.length; i < len; i++) {
40
- let cb = topicCallbacks[i];
41
- if (cb.toString() != callback.toString()) {
42
- newTopicCallbacks.push(callback);
43
- }
44
- }
45
- if (newTopicCallbacks.length == 0) {
46
- Dispatch.callbacksByTopic.delete(topic);
47
- } else {
48
- Dispatch.callbacksByTopic.set(topic, newTopicCallbacks);
49
- }
50
- }
51
- }
52
-
53
- // Calls all the callbacks to this particular topic. Returns a Promise which resolves when ALL
54
- // of the topic callbacks have also resolved, or in the same event loop if they are synchronous.
55
- public static async publish(topic:DispatchTopic, details?:any):Promise<void> {
56
- if (Dispatch.callbacksByTopic.has(topic)) {
57
- let topicCallbackResults = [];
58
- let errors = [];
59
- let subjectSubscribers = Dispatch.callbacksByTopic.get(topic);
60
- if (Dispatch.debug) {
61
- console.log(`Dispatching '${topic}' to ${subjectSubscribers.length} subscribers, with details: ${JSON.stringify(details)}`);
62
- }
63
- for (let i = 0, len = subjectSubscribers.length; i < len; i++) {
64
- let callback = subjectSubscribers[i];
65
- // catch errors here so we don't interrupt any of the other callbacks
66
- let result;
67
- try {
68
- result = callback(topic, details);
69
- topicCallbackResults.push(result);
70
- } catch (e) {
71
- errors.push(e);
72
- }
73
- }
74
- await Promise.all(topicCallbackResults);
75
- if (errors.length > 0) {
76
- return Promise.reject(errors);
77
- }
78
- return Promise.resolve();
79
- } else if (Dispatch.debug) {
80
- console.log(`Dispatch has no subscribers to topic '${topic}'`);
81
- }
82
- }
83
-
84
- // Fire off a sequence of messages. Waits for the preceding message callbacks to finish / resolve
85
- // before publishing the next (if the first message throws an exception, this short-circuits).
86
- public static async sequence(messages:DispatchMessage[]):Promise<void> {
87
- for (let i = 0, len = messages.length; i < len; i++) {
88
- let message:DispatchMessage = messages[i];
89
- await Dispatch.publish(message.topic, message.details);
90
- }
91
- }
92
- }
@@ -1,194 +0,0 @@
1
- export class NumberFormat {
2
-
3
- private static readonly ORDINAL_REGEX:RegExp = /^\d*(?:1st|2nd|3rd|[04-9]th|1[23]th)$/i;
4
-
5
- private static readonly NUMERIC_WORD_SEQUENCE:RegExp = /(?:one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|(?:thir|four|fif|six|seven|eigh|nine)teen|(?:twen|thir|for|fif|six|seven|eigh|nine)ty|[mb]illion|thousand|hundred)(?:(?:\s*(?:\sand\s+|-\s*)(?:one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|(?:thir|four|fif|six|seven|eigh|nine)teen|(?:twen|thir|for|fif|six|seven|eigh|nine)ty|[mb]illion|thousand|hundred)))*/i;
6
- private static readonly ROMAN_NUMERALS:RegExp = /\b[MDCLXVI]+\b/i;
7
-
8
- public static commas(value:number, keepFractions:boolean):string {
9
- if (!Number.isFinite(value)) {
10
- return "0"; // We never want to show "NaN" or "Infinity" in shaxpir. Zero is always preferable.
11
- }
12
- let original:number = value;
13
- let isNegative:boolean = value < 0;
14
- let absValue:number = Math.abs(value);
15
- let floorValue:number = Math.floor(absValue);
16
- let v:number = floorValue;
17
- let formatted:string = "";
18
- if (v === 0) {
19
- formatted = "0";
20
- }
21
- while (v > 0) {
22
- if (formatted.length > 0) {
23
- formatted = "," + formatted;
24
- }
25
- let remainder:number = (v % 1000);
26
- v = Math.floor(v / 1000);
27
- if (v > 0) {
28
- if (remainder < 10) {
29
- formatted = "00" + remainder + formatted;
30
- } else if (remainder < 100) {
31
- formatted = "0" + remainder + formatted;
32
- } else {
33
- formatted = remainder + formatted;
34
- }
35
- } else {
36
- formatted = remainder + formatted;
37
- }
38
- }
39
- if (keepFractions && absValue !== floorValue) {
40
- formatted += "." + original.toString().split('.')[1];
41
- }
42
- if (isNegative) {
43
- formatted = "-" + formatted;
44
- }
45
- return formatted;
46
- }
47
-
48
- public static ordinal(value:number):string {
49
- if (value == 1 || (value % 10 == 1 && value != 11)) {
50
- return "st";
51
- } else if (value == 2 || (value % 10 == 2 && value != 12)) {
52
- return "nd";
53
- } else if (value == 3 || (value % 10 == 3 && value != 13)) {
54
- return "rd";
55
- } else {
56
- return "th";
57
- }
58
- }
59
-
60
- public static isOrdinal(text:string):boolean {
61
- return NumberFormat.ORDINAL_REGEX.test(text);
62
- }
63
-
64
- public static dollarsFromCents(value:number):string {
65
- let dollars:number = Math.floor(value / 100);
66
- let cents:number = value - (dollars * 100);
67
- if (cents === 0) {
68
- return "$" + dollars + ".00";
69
- } else if (cents < 10) {
70
- return "$" + dollars + ".0" + cents;
71
- } else {
72
- return "$" + dollars + "." + cents;
73
- }
74
- }
75
-
76
- public static percent(value:number, fractionDigits:number = 0):string {
77
- let numbers:string = NumberFormat.commas(value * 100, fractionDigits > 0);
78
- if (fractionDigits > 0 && value !== 0) {
79
- let indexOfDecimal:number = numbers.lastIndexOf(".");
80
- if (indexOfDecimal >= 0) {
81
- let numsBeforeDecimal:string = numbers.substring(0, indexOfDecimal);
82
- let numsAfterDecimal:string = numbers.substring(indexOfDecimal + 1);
83
- if (numsAfterDecimal.length > fractionDigits) {
84
- numbers = numsBeforeDecimal + "." + numsAfterDecimal.substring(0, fractionDigits);
85
- }
86
- }
87
- }
88
- return numbers + "%";
89
- }
90
-
91
- public static text(value:number):string {
92
- let isNegative:boolean = value < 0;
93
- value = Math.abs(Math.round(value));
94
- let asText:string;
95
- if (value == 0) {
96
- asText = "zero";
97
- } else if (value == 1) {
98
- asText = "one";
99
- } else if (value == 2) {
100
- asText = "two";
101
- } else if (value == 3) {
102
- asText = "three";
103
- } else if (value == 4) {
104
- asText = "four";
105
- } else if (value == 5) {
106
- asText = "five";
107
- } else if (value == 6) {
108
- asText = "six";
109
- } else if (value == 7) {
110
- asText = "seven";
111
- } else if (value == 8) {
112
- asText = "eight";
113
- } else if (value == 9) {
114
- asText = "nine";
115
- } else if (value == 10) {
116
- asText = "ten";
117
- } else if (value == 11) {
118
- asText = "eleven";
119
- } else if (value == 12) {
120
- asText = "twelve";
121
- } else if (value == 13) {
122
- asText = "thirteen";
123
- } else if (value == 14) {
124
- asText = "fourteen";
125
- } else if (value == 15) {
126
- asText = "fifteen";
127
- } else if (value == 16) {
128
- asText = "sixteen";
129
- } else if (value == 17) {
130
- asText = "seventeen";
131
- } else if (value == 18) {
132
- asText = "eighteen";
133
- } else if (value == 19) {
134
- asText = "nineteen";
135
- } else if (value >= 20 && value <= 99) {
136
- let tensPlace = Math.floor(value / 10);
137
- let onesPlace = value % 10;
138
- if (tensPlace == 2) {
139
- asText = "twenty";
140
- } else if (tensPlace == 3) {
141
- asText = "thirty";
142
- } else if (tensPlace == 4) {
143
- asText = "forty";
144
- } else if (tensPlace == 5) {
145
- asText = "fifty";
146
- } else if (tensPlace == 6) {
147
- asText = "sixty";
148
- } else if (tensPlace == 7) {
149
- asText = "seventy";
150
- } else if (tensPlace == 8) {
151
- asText = "eighty";
152
- } else if (tensPlace == 9) {
153
- asText = "ninety";
154
- }
155
- if (onesPlace !== 0) {
156
- asText += "-" + NumberFormat.text(onesPlace);
157
- }
158
- } else if (value >= 100 && value <= 999) {
159
- let hundredsPlace = Math.floor(value / 100);
160
- asText = NumberFormat.text(hundredsPlace) + " hundred " + NumberFormat.text(value - (hundredsPlace * 100));
161
- } else if (value >= 1000 && value <= 9999) {
162
- let thousandsPlace = Math.floor(value / 1000);
163
- asText = NumberFormat.text(thousandsPlace) + " thousand " + NumberFormat.text(value - (thousandsPlace * 1000));
164
- }
165
- if (isNegative) {
166
- asText = "minus " + asText;
167
- }
168
- return asText;
169
- }
170
-
171
- public static findNumericWordSequence(text:string):string {
172
- let result = NumberFormat.NUMERIC_WORD_SEQUENCE.exec(text);
173
- if (result !== null) {
174
- return result[0];
175
- }
176
- return null;
177
- }
178
-
179
- public static findRomanNumerals(text:string):string {
180
- let result = NumberFormat.ROMAN_NUMERALS.exec(text);
181
- if (result !== null) {
182
- return result[0];
183
- }
184
- return null;
185
- }
186
-
187
- public static asHex(value:number, padToLength:number = 1):string {
188
- let hex:string = Math.floor(value).toString(16);
189
- while (hex.length < padToLength) {
190
- hex = "0" + hex;
191
- }
192
- return hex;
193
- }
194
- }
@@ -1,14 +0,0 @@
1
- import rfdc = require('rfdc');
2
- import isEqual = require('fast-deep-equal');
3
- const cloneDeep = rfdc();
4
-
5
- export class Struct {
6
-
7
- public static clone(value:any):any {
8
- return cloneDeep(value);
9
- }
10
-
11
- public static equals(a:any, b:any):boolean {
12
- return isEqual(a, b);
13
- }
14
- }
@@ -1,131 +0,0 @@
1
-
2
- import { JsonPath, PathVal } from "../models/markup/Operation";
3
- import { Struct } from "./Struct";
4
-
5
- export class Tuples {
6
-
7
- public static of(value:any):PathVal[] {
8
- let tuples:PathVal[] = [];
9
- if (Array.isArray(value)) {
10
- Tuples.collectFromArray(tuples, [], value);
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
-
20
- public static stringifyPath(prefix:string, path:JsonPath):string {
21
- if (prefix == null || prefix.trim() == "") {
22
- prefix = "$";
23
- }
24
- if (!prefix.startsWith("$")) {
25
- prefix = "$" + prefix;
26
- }
27
- let str = prefix;
28
- for (let i = 0; i < path.length; i++) {
29
- let pathItem = path[i];
30
- if (typeof(pathItem) === 'string') {
31
- str += '.' + pathItem;
32
- } else {
33
- str += '[' + pathItem + ']';
34
- }
35
- }
36
- return str;
37
- }
38
-
39
- private static collectFromArray(tuples:PathVal[], path:JsonPath, array:any[]):void {
40
- for (let i = 0; i < array.length; i++) {
41
- path.push(i);
42
- let item = array[i];
43
- Tuples.collectTuplesAtPath(tuples, path, item);
44
- path.pop();
45
- }
46
- }
47
-
48
- private static collectFromObject(tuples:PathVal[], path:JsonPath, object:any):void {
49
- const keys = Object.keys(object);
50
- for (let i = 0; i < keys.length; i++) {
51
- const key = keys[i];
52
- if (object.hasOwnProperty(key)) {
53
- path.push(key);
54
- let item = object[key];
55
- Tuples.collectTuplesAtPath(tuples, path, item);
56
- path.pop();
57
- }
58
- }
59
- }
60
-
61
- private static collectTuplesAtPath(tuples:PathVal[], path:JsonPath, item:any):void {
62
- if (Struct.equals(item, {}) || Struct.equals(item, [])) {
63
- tuples.push({ path : Struct.clone(path) as JsonPath, val : item });
64
- } else if (Array.isArray(item)) {
65
- Tuples.collectFromArray(tuples, path, item);
66
- } else {
67
- const type = typeof(item);
68
- if (
69
- item === null ||
70
- type === "string" ||
71
- type === "number" ||
72
- type === "boolean"
73
- ) {
74
- tuples.push({ path : Struct.clone(path) as JsonPath, val : item });
75
- } else if (type === "function" || type == "symbol" || type == "bigint" || type === "undefined") {
76
- throw new Error(`can't create tuple from '${type}' item at path: ${JSON.stringify(path)}`);
77
- } else {
78
- Tuples.collectFromObject(tuples, path, item);
79
- }
80
- }
81
- }
82
-
83
- private static sort(tuples:PathVal[]):PathVal[] {
84
- // NOTE: tuples are sorted ONLY according to their PATH. The val is never considered. This is
85
- // because we assume there can never be two identical paths anyhow, in a valid JSON tuple array.
86
- tuples.sort((a:PathVal, b:PathVal) => {
87
- const aPath = a.path;
88
- const bPath = b.path;
89
- const aPathLength = aPath.length;
90
- const bPathLength = bPath.length;
91
- let length = Math.min(aPathLength, bPathLength);
92
- for (let i = 0; i < length; i++) {
93
- const aPathElement = aPath[i];
94
- const bPathElement = bPath[i];
95
- const aPathElementType = typeof(aPathElement);
96
- const bPathElementType = typeof(bPathElement);
97
- let comparison = 0;
98
- if (aPathElementType === "string" && bPathElementType === "string") {
99
- const aString = aPathElement as string;
100
- const bString = bPathElement as string;
101
- comparison = aString.localeCompare(bString);
102
- } else if (aPathElementType === "number" && bPathElementType === "number") {
103
- const aNumber = aPathElement as number;
104
- const bNumber = bPathElement as number;
105
- if (aNumber < bNumber) {
106
- comparison = -1;
107
- } else if (aNumber > bNumber) {
108
- comparison = 1;
109
- }
110
- } else if (aPathElementType === "string" && bPathElementType === "number") {
111
- comparison = -1;
112
- } else if (aPathElementType === "number" && bPathElementType === "string") {
113
- comparison = 1;
114
- }
115
- if (comparison !== 0) {
116
- return comparison;
117
- }
118
- }
119
- if (aPathLength < bPathLength) {
120
- return -1;
121
- } else if (aPathLength > bPathLength) {
122
- return 1;
123
- } else {
124
- // If we never do want to incorporate value comparisons into sort order, this is where we'd do it.
125
- return 0;
126
- }
127
- });
128
- return tuples;
129
- }
130
-
131
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes