@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.
Files changed (211) hide show
  1. package/README.md +1 -0
  2. package/decs.d.ts +87 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.js +20 -0
  5. package/dist/models/OutboundMessage.d.ts +18 -0
  6. package/dist/models/OutboundMessage.js +25 -0
  7. package/dist/models/content/Activity.d.ts +10 -0
  8. package/dist/models/content/Activity.js +2 -0
  9. package/dist/models/content/ArrayView.d.ts +26 -0
  10. package/dist/models/content/ArrayView.js +174 -0
  11. package/dist/models/content/Billing.d.ts +144 -0
  12. package/dist/models/content/Billing.js +418 -0
  13. package/dist/models/content/Book.d.ts +77 -0
  14. package/dist/models/content/Book.js +407 -0
  15. package/dist/models/content/Category.d.ts +16 -0
  16. package/dist/models/content/Category.js +20 -0
  17. package/dist/models/content/Checkpointable.d.ts +21 -0
  18. package/dist/models/content/Checkpointable.js +156 -0
  19. package/dist/models/content/Comment.d.ts +19 -0
  20. package/dist/models/content/Comment.js +53 -0
  21. package/dist/models/content/ConceptArt.d.ts +31 -0
  22. package/dist/models/content/ConceptArt.js +84 -0
  23. package/dist/models/content/Content.d.ts +52 -0
  24. package/dist/models/content/Content.js +61 -0
  25. package/dist/models/content/ContentKind.d.ts +10 -0
  26. package/dist/models/content/ContentKind.js +16 -0
  27. package/dist/models/content/Context.d.ts +28 -0
  28. package/dist/models/content/Context.js +162 -0
  29. package/dist/models/content/DevEnv.d.ts +5 -0
  30. package/dist/models/content/DevEnv.js +9 -0
  31. package/dist/models/content/Device.d.ts +24 -0
  32. package/dist/models/content/Device.js +62 -0
  33. package/dist/models/content/Dictionary.d.ts +31 -0
  34. package/dist/models/content/Dictionary.js +5 -0
  35. package/dist/models/content/DictionaryEntry.d.ts +20 -0
  36. package/dist/models/content/DictionaryEntry.js +2 -0
  37. package/dist/models/content/ElasticModel.d.ts +149 -0
  38. package/dist/models/content/ElasticModel.js +179 -0
  39. package/dist/models/content/Environment.d.ts +61 -0
  40. package/dist/models/content/Environment.js +124 -0
  41. package/dist/models/content/ExportOptions.d.ts +64 -0
  42. package/dist/models/content/ExportOptions.js +213 -0
  43. package/dist/models/content/Folder.d.ts +16 -0
  44. package/dist/models/content/Folder.js +33 -0
  45. package/dist/models/content/Fragment.d.ts +54 -0
  46. package/dist/models/content/Fragment.js +181 -0
  47. package/dist/models/content/GeoLocation.d.ts +4 -0
  48. package/dist/models/content/GeoLocation.js +2 -0
  49. package/dist/models/content/Hanzi.d.ts +21 -0
  50. package/dist/models/content/Hanzi.js +2 -0
  51. package/dist/models/content/HighlightRule.d.ts +9 -0
  52. package/dist/models/content/HighlightRule.js +2 -0
  53. package/dist/models/content/Manifest.d.ts +42 -0
  54. package/dist/models/content/Manifest.js +114 -0
  55. package/dist/models/content/Media.d.ts +32 -0
  56. package/dist/models/content/Media.js +98 -0
  57. package/dist/models/content/Metric.d.ts +46 -0
  58. package/dist/models/content/Metric.js +183 -0
  59. package/dist/models/content/Migration.d.ts +68 -0
  60. package/dist/models/content/Migration.js +155 -0
  61. package/dist/models/content/Model.d.ts +45 -0
  62. package/dist/models/content/Model.js +280 -0
  63. package/dist/models/content/Permissions.d.ts +7 -0
  64. package/dist/models/content/Permissions.js +20 -0
  65. package/dist/models/content/Phrase.d.ts +8 -0
  66. package/dist/models/content/Phrase.js +2 -0
  67. package/dist/models/content/Placeholder.d.ts +8 -0
  68. package/dist/models/content/Placeholder.js +36 -0
  69. package/dist/models/content/Profile.d.ts +30 -0
  70. package/dist/models/content/Profile.js +95 -0
  71. package/dist/models/content/RichText.d.ts +58 -0
  72. package/dist/models/content/RichText.js +79 -0
  73. package/dist/models/content/Session.d.ts +39 -0
  74. package/dist/models/content/Session.js +173 -0
  75. package/dist/models/content/Speech.d.ts +67 -0
  76. package/dist/models/content/Speech.js +97 -0
  77. package/dist/models/content/Stub.d.ts +24 -0
  78. package/dist/models/content/Stub.js +179 -0
  79. package/dist/models/content/Time.d.ts +56 -0
  80. package/dist/models/content/Time.js +295 -0
  81. package/dist/models/content/User.d.ts +36 -0
  82. package/dist/models/content/User.js +95 -0
  83. package/dist/models/content/Workspace.d.ts +71 -0
  84. package/dist/models/content/Workspace.js +237 -0
  85. package/dist/models/content/index.d.ts +36 -0
  86. package/dist/models/content/index.js +53 -0
  87. package/dist/models/index.d.ts +4 -0
  88. package/dist/models/index.js +21 -0
  89. package/dist/models/legacy/LegacyBodyFormat.d.ts +9 -0
  90. package/dist/models/legacy/LegacyBodyFormat.js +2 -0
  91. package/dist/models/legacy/LegacyComment.d.ts +12 -0
  92. package/dist/models/legacy/LegacyComment.js +2 -0
  93. package/dist/models/legacy/LegacyContent.d.ts +53 -0
  94. package/dist/models/legacy/LegacyContent.js +55 -0
  95. package/dist/models/legacy/LegacyConversion.d.ts +55 -0
  96. package/dist/models/legacy/LegacyConversion.js +401 -0
  97. package/dist/models/legacy/LegacyFragment.d.ts +21 -0
  98. package/dist/models/legacy/LegacyFragment.js +2 -0
  99. package/dist/models/legacy/LegacyLocator.d.ts +8 -0
  100. package/dist/models/legacy/LegacyLocator.js +31 -0
  101. package/dist/models/legacy/LegacyOutboundMessage.d.ts +16 -0
  102. package/dist/models/legacy/LegacyOutboundMessage.js +13 -0
  103. package/dist/models/legacy/LegacyPicture.d.ts +14 -0
  104. package/dist/models/legacy/LegacyPicture.js +2 -0
  105. package/dist/models/legacy/LegacyProfile.d.ts +9 -0
  106. package/dist/models/legacy/LegacyProfile.js +2 -0
  107. package/dist/models/legacy/LegacySession.d.ts +41 -0
  108. package/dist/models/legacy/LegacySession.js +35 -0
  109. package/dist/models/legacy/LegacyStory.d.ts +23 -0
  110. package/dist/models/legacy/LegacyStory.js +2 -0
  111. package/dist/models/legacy/LegacyStub.d.ts +15 -0
  112. package/dist/models/legacy/LegacyStub.js +2 -0
  113. package/dist/models/legacy/LegacyTransaction.d.ts +14 -0
  114. package/dist/models/legacy/LegacyTransaction.js +49 -0
  115. package/dist/models/legacy/LegacyUser.d.ts +28 -0
  116. package/dist/models/legacy/LegacyUser.js +32 -0
  117. package/dist/models/legacy/LegacyWorkspace.d.ts +23 -0
  118. package/dist/models/legacy/LegacyWorkspace.js +6 -0
  119. package/dist/models/legacy/index.d.ts +15 -0
  120. package/dist/models/legacy/index.js +32 -0
  121. package/dist/models/markup/BodyFormat.d.ts +14 -0
  122. package/dist/models/markup/BodyFormat.js +190 -0
  123. package/dist/models/markup/ChangeModel.d.ts +22 -0
  124. package/dist/models/markup/ChangeModel.js +107 -0
  125. package/dist/models/markup/DeltaOps.d.ts +5 -0
  126. package/dist/models/markup/DeltaOps.js +74 -0
  127. package/dist/models/markup/HtmlMarkup.d.ts +4 -0
  128. package/dist/models/markup/HtmlMarkup.js +21 -0
  129. package/dist/models/markup/Operation.d.ts +32 -0
  130. package/dist/models/markup/Operation.js +194 -0
  131. package/dist/models/markup/TextEditOps.d.ts +9 -0
  132. package/dist/models/markup/TextEditOps.js +50 -0
  133. package/dist/models/markup/index.d.ts +6 -0
  134. package/dist/models/markup/index.js +23 -0
  135. package/dist/repo/ConnectionListener.d.ts +9 -0
  136. package/dist/repo/ConnectionListener.js +21 -0
  137. package/dist/repo/PermissiveJson1.d.ts +58 -0
  138. package/dist/repo/PermissiveJson1.js +39 -0
  139. package/dist/repo/ShareSync.d.ts +60 -0
  140. package/dist/repo/ShareSync.js +348 -0
  141. package/dist/repo/index.d.ts +3 -0
  142. package/dist/repo/index.js +20 -0
  143. package/dist/util/Async.d.ts +8 -0
  144. package/dist/util/Async.js +18 -0
  145. package/dist/util/Base62.d.ts +6 -0
  146. package/dist/util/Base62.js +47 -0
  147. package/dist/util/BinarySearch.d.ts +7 -0
  148. package/dist/util/BinarySearch.js +46 -0
  149. package/dist/util/CachingHasher.d.ts +8 -0
  150. package/dist/util/CachingHasher.js +41 -0
  151. package/dist/util/Color.d.ts +32 -0
  152. package/dist/util/Color.js +204 -0
  153. package/dist/util/Dispatch.d.ts +15 -0
  154. package/dist/util/Dispatch.js +79 -0
  155. package/dist/util/EditDistance.d.ts +13 -0
  156. package/dist/util/EditDistance.js +184 -0
  157. package/dist/util/Encryption.d.ts +5 -0
  158. package/dist/util/Encryption.js +2 -0
  159. package/dist/util/Logging.d.ts +108 -0
  160. package/dist/util/Logging.js +412 -0
  161. package/dist/util/NumberFormat.d.ts +14 -0
  162. package/dist/util/NumberFormat.js +224 -0
  163. package/dist/util/Struct.d.ts +4 -0
  164. package/dist/util/Struct.js +15 -0
  165. package/dist/util/Template.d.ts +16 -0
  166. package/dist/util/Template.js +128 -0
  167. package/dist/util/Text.d.ts +45 -0
  168. package/dist/util/Text.js +243 -0
  169. package/dist/util/Tuples.d.ts +9 -0
  170. package/dist/util/Tuples.js +135 -0
  171. package/dist/util/Validate.d.ts +4 -0
  172. package/dist/util/Validate.js +11 -0
  173. package/dist/util/Vocabulary.d.ts +3 -0
  174. package/dist/util/Vocabulary.js +35 -0
  175. package/dist/util/index.d.ts +16 -0
  176. package/dist/util/index.js +33 -0
  177. package/lib/models/content/ArrayView.ts +203 -0
  178. package/lib/models/content/Billing.ts +558 -0
  179. package/lib/models/content/Content.ts +110 -0
  180. package/lib/models/content/ContentKind.ts +14 -0
  181. package/lib/models/content/DevEnv.ts +5 -0
  182. package/lib/models/content/Device.ts +86 -0
  183. package/lib/models/content/DictionaryEntry.ts +22 -0
  184. package/lib/models/content/GeoLocation.ts +4 -0
  185. package/lib/models/content/Hanzi.ts +25 -0
  186. package/lib/models/content/Manifest.ts +162 -0
  187. package/lib/models/content/Media.ts +126 -0
  188. package/lib/models/content/Model.ts +327 -0
  189. package/lib/models/content/Permissions.ts +21 -0
  190. package/lib/models/content/Phrase.ts +10 -0
  191. package/lib/models/content/Profile.ts +119 -0
  192. package/lib/models/content/Time.ts +328 -0
  193. package/lib/models/content/User.ts +130 -0
  194. package/lib/models/markup/ChangeModel.ts +95 -0
  195. package/lib/models/markup/DeltaOps.ts +71 -0
  196. package/lib/models/markup/Operation.ts +215 -0
  197. package/lib/models/markup/TextEditOps.ts +50 -0
  198. package/lib/repo/ConnectionListener.ts +25 -0
  199. package/lib/repo/PermissiveJson1.ts +14 -0
  200. package/lib/repo/ShareSync.ts +390 -0
  201. package/lib/util/Base62.ts +47 -0
  202. package/lib/util/CachingHasher.ts +38 -0
  203. package/lib/util/Dispatch.ts +92 -0
  204. package/lib/util/Encryption.ts +5 -0
  205. package/lib/util/Logging.ts +568 -0
  206. package/lib/util/NumberFormat.ts +194 -0
  207. package/lib/util/Struct.ts +14 -0
  208. package/lib/util/Tuples.ts +131 -0
  209. package/package.json +41 -0
  210. package/tsconfig.json +25 -0
  211. package/tslint.json +46 -0
@@ -0,0 +1,194 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,131 @@
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
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@shaxpir/duiduidui-models",
3
+ "version": "1.0.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/shaxpir/duiduidui-models"
7
+ },
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "mocha tests",
11
+ "test:watch": "mocha -w tests"
12
+ },
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "dependencies": {
16
+ "@shaxpir/quill-delta": "^6.1.1",
17
+ "@shaxpir/rich-text": "^5.0.2",
18
+ "@shaxpir/sharedb": "^5.3.0",
19
+ "dayjs": "1.11.7",
20
+ "hsluv": "latest",
21
+ "ot-json1": "1.0.1",
22
+ "ot-text-unicode": "4.0.0",
23
+ "fast-array-diff": "1.0.1",
24
+ "json-diff-ts": "1.2.4",
25
+ "md5": "2.x",
26
+ "pluralize": "latest",
27
+ "reconnecting-websocket": "4.4.0",
28
+ "fast-deep-equal": "^3.1.3",
29
+ "rfdc": "^1.1.4"
30
+ },
31
+ "devDependencies": {
32
+ "@types/lodash": "latest",
33
+ "@types/md5": "^2.1.33",
34
+ "@types/node": "^18.0.50",
35
+ "@types/pluralize": "0.0.29",
36
+ "chai": "^4.3.7",
37
+ "mocha": "^10.2.0",
38
+ "tslint": "^5.12.1",
39
+ "typescript": "latest"
40
+ }
41
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "outDir": "./dist",
5
+ "noImplicitAny": true,
6
+ "alwaysStrict": true,
7
+ "target": "es2021",
8
+ "declaration": true,
9
+ "moduleResolution": "node",
10
+ "resolveJsonModule": true,
11
+ "esModuleInterop": true,
12
+ "allowSyntheticDefaultImports":true,
13
+ "typeRoots": [
14
+ "./node_modules/@types"
15
+ ]
16
+ },
17
+ "include": [
18
+ "./lib/**/*",
19
+ "decs.d.ts"
20
+ ],
21
+ "baseUrl": "types",
22
+ "typeRoots": [
23
+ "types"
24
+ ]
25
+ }
package/tslint.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "extends": "tslint:recommended",
3
+ "rules": {
4
+ "eofline": false,
5
+ "interface-name": false,
6
+ "max-classes-per-file": false,
7
+ "max-line-length": {
8
+ "options": [120]
9
+ },
10
+ "member-access": true,
11
+ "member-ordering": false,
12
+ "new-parens": true,
13
+ "no-arg": true,
14
+ "no-bitwise": true,
15
+ "no-conditional-assignment": true,
16
+ "no-consecutive-blank-lines": false,
17
+ "no-console": {
18
+ "severity": "warning",
19
+ "options": ["debug", "info", "log", "time", "timeEnd", "trace"]
20
+ },
21
+ "no-unused-variable": true,
22
+ "object-literal-key-quotes": false,
23
+ "object-literal-shorthand": false,
24
+ "object-literal-sort-keys": false,
25
+ "only-arrow-functions": false,
26
+ "prefer-const": false,
27
+ "prefer-for-of": false,
28
+ "quotemark": false,
29
+ "radix": false,
30
+ "trailing-comma": false,
31
+ "typedef": [true, "call-signature", "parameter"],
32
+ "typedef-whitespace": [true, {}, {
33
+ "call-signature": "nospace",
34
+ "parameter": "nospace",
35
+ "property-declaration": "nospace",
36
+ "variable-declaration": "nospace"
37
+ }],
38
+ "variable-name": false,
39
+ "whitespace": false
40
+ },
41
+ "jsRules": {
42
+ "max-line-length": {
43
+ "options": [120]
44
+ }
45
+ }
46
+ }