@fable-org/fable-library-js 1.6.0 → 1.7.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/CHANGELOG.md +6 -0
- package/CollectionUtil.d.ts +7 -0
- package/CollectionUtil.js +182 -0
- package/String.d.ts +10 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function count<T>(col: Iterable<T>): number;
|
|
2
|
+
export declare function isReadOnly<T>(col: Iterable<T>): boolean;
|
|
3
|
+
export declare function copyTo<T>(col: Iterable<T>, array: T[], arrayIndex: number): void;
|
|
4
|
+
export declare function contains<T>(col: Iterable<T>, item: T): boolean;
|
|
5
|
+
export declare function add<T>(col: Iterable<T>, item: T): void;
|
|
6
|
+
export declare function remove<T>(col: Iterable<T>, item: T): boolean;
|
|
7
|
+
export declare function clear<T>(col: Iterable<T>): void;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { equals, isArrayLike } from "./Util.js";
|
|
2
|
+
export function count(col) {
|
|
3
|
+
if (typeof col["System.Collections.Generic.ICollection`1.get_Count"] === "function") {
|
|
4
|
+
return col["System.Collections.Generic.ICollection`1.get_Count"](); // collection
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
if (typeof col["System.Collections.Generic.IReadOnlyCollection`1.get_Count"] === "function") {
|
|
8
|
+
return col["System.Collections.Generic.IReadOnlyCollection`1.get_Count"](); // collection
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
if (isArrayLike(col)) {
|
|
12
|
+
return col.length; // array, resize array
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
if (typeof col.size === "number") {
|
|
16
|
+
return col.size; // map, set
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
let count = 0;
|
|
20
|
+
for (const _ of col) {
|
|
21
|
+
count++;
|
|
22
|
+
}
|
|
23
|
+
return count; // other collections
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function isReadOnly(col) {
|
|
30
|
+
if (typeof col["System.Collections.Generic.ICollection`1.get_IsReadOnly"] === "function") {
|
|
31
|
+
return col["System.Collections.Generic.ICollection`1.get_IsReadOnly"](); // collection
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (isArrayLike(col)) {
|
|
35
|
+
return ArrayBuffer.isView(col); // true for typed arrays, false for other arrays
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (typeof col.size === "number") {
|
|
39
|
+
return false; // map, set
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return true; // other collections
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function copyTo(col, array, arrayIndex) {
|
|
48
|
+
if (typeof col["System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"] === "function") {
|
|
49
|
+
col["System.Collections.Generic.ICollection`1.CopyToZ3B4C077E"](array, arrayIndex); // collection
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
let i = arrayIndex;
|
|
53
|
+
for (const v of col) {
|
|
54
|
+
array[i] = v;
|
|
55
|
+
i++;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function contains(col, item) {
|
|
60
|
+
if (typeof col["System.Collections.Generic.ICollection`1.Contains2B595"] === "function") {
|
|
61
|
+
return col["System.Collections.Generic.ICollection`1.Contains2B595"](item); // collection
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
if (isArrayLike(col)) {
|
|
65
|
+
let i = col.findIndex(x => equals(x, item)); // array, resize array
|
|
66
|
+
return i >= 0;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (typeof col.has === "function") {
|
|
70
|
+
if (typeof col.set === "function" && isArrayLike(item)) {
|
|
71
|
+
return col.has(item[0]) && equals(col.get(item[0]), item[1]); // map
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return col.has(item); // set
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return false; // other collections
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function add(col, item) {
|
|
84
|
+
if (typeof col["System.Collections.Generic.ICollection`1.Add2B595"] === "function") {
|
|
85
|
+
return col["System.Collections.Generic.ICollection`1.Add2B595"](item); // collection
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (isArrayLike(col)) {
|
|
89
|
+
if (ArrayBuffer.isView(col)) {
|
|
90
|
+
// TODO: throw for typed arrays?
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
col.push(item); // array, resize array
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (typeof col.add === "function") {
|
|
98
|
+
return col.add(item); // set
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (typeof col.has === "function"
|
|
102
|
+
&& typeof col.set === "function"
|
|
103
|
+
&& isArrayLike(item)) {
|
|
104
|
+
if (col.has(item[0]) === false) {
|
|
105
|
+
col.set(item[0], item[1]); // map
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error("An item with the same key has already been added. Key: " + item[0]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// TODO: throw for other collections?
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function remove(col, item) {
|
|
119
|
+
if (typeof col["System.Collections.Generic.ICollection`1.Remove2B595"] === "function") {
|
|
120
|
+
return col["System.Collections.Generic.ICollection`1.Remove2B595"](item); // collection
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
if (isArrayLike(col)) {
|
|
124
|
+
if (ArrayBuffer.isView(col)) {
|
|
125
|
+
// TODO: throw for typed arrays
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
let i = col.findIndex(x => equals(x, item));
|
|
130
|
+
if (i >= 0) {
|
|
131
|
+
col.splice(i, 1); // array, resize array
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (typeof col.delete === "function") {
|
|
141
|
+
if (typeof col.set === "function" && isArrayLike(item)) {
|
|
142
|
+
if (col.has(item[0]) && equals(col.get(item[0]), item[1])) {
|
|
143
|
+
return col.delete(item[0]); // map
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return col.delete(item); // set
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// TODO: throw for other collections?
|
|
155
|
+
return false; // other collections
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export function clear(col) {
|
|
161
|
+
if (typeof col["System.Collections.Generic.ICollection`1.Clear"] === "function") {
|
|
162
|
+
return col["System.Collections.Generic.ICollection`1.Clear"](); // collection
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
if (isArrayLike(col)) {
|
|
166
|
+
if (ArrayBuffer.isView(col)) {
|
|
167
|
+
// TODO: throw for typed arrays?
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
col.splice(0); // array, resize array
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
if (typeof col.clear === "function") {
|
|
175
|
+
col.clear(); // map, set
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
// TODO: throw for other collections?
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
package/String.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
declare const enum StringComparison {
|
|
2
|
+
CurrentCulture = 0,
|
|
3
|
+
CurrentCultureIgnoreCase = 1,
|
|
4
|
+
InvariantCulture = 2,
|
|
5
|
+
InvariantCultureIgnoreCase = 3,
|
|
6
|
+
Ordinal = 4,
|
|
7
|
+
OrdinalIgnoreCase = 5
|
|
8
|
+
}
|
|
1
9
|
export declare function compare(...args: any[]): number;
|
|
2
10
|
export declare function compareOrdinal(x: string, y: string): number;
|
|
3
11
|
export declare function compareTo(x: string, y: string): number;
|
|
4
|
-
export declare function startsWith(str: string, pattern: string, ic:
|
|
5
|
-
export declare function endsWith(str: string, pattern: string, ic:
|
|
12
|
+
export declare function startsWith(str: string, pattern: string, ic: boolean | StringComparison): boolean;
|
|
13
|
+
export declare function endsWith(str: string, pattern: string, ic: boolean | StringComparison): boolean;
|
|
6
14
|
export declare function indexOfAny(str: string, anyOf: string[], ...args: number[]): number;
|
|
7
15
|
export type IPrintfFormatContinuation = (f: (x: string) => any) => any;
|
|
8
16
|
export interface IPrintfFormat {
|
package/package.json
CHANGED