yummies 3.0.34 → 3.0.35

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/encodings.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function unicodeToWin1251(s: string): string;
2
+ //# sourceMappingURL=encodings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodings.d.ts","sourceRoot":"","sources":["../src/encodings.ts"],"names":[],"mappings":"AAoQA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,UAazC"}
package/encodings.js ADDED
@@ -0,0 +1,269 @@
1
+ const DMap = {
2
+ 0: 0,
3
+ 1: 1,
4
+ 2: 2,
5
+ 3: 3,
6
+ 4: 4,
7
+ 5: 5,
8
+ 6: 6,
9
+ 7: 7,
10
+ 8: 8,
11
+ 9: 9,
12
+ 10: 10,
13
+ 11: 11,
14
+ 12: 12,
15
+ 13: 13,
16
+ 14: 14,
17
+ 15: 15,
18
+ 16: 16,
19
+ 17: 17,
20
+ 18: 18,
21
+ 19: 19,
22
+ 20: 20,
23
+ 21: 21,
24
+ 22: 22,
25
+ 23: 23,
26
+ 24: 24,
27
+ 25: 25,
28
+ 26: 26,
29
+ 27: 27,
30
+ 28: 28,
31
+ 29: 29,
32
+ 30: 30,
33
+ 31: 31,
34
+ 32: 32,
35
+ 33: 33,
36
+ 34: 34,
37
+ 35: 35,
38
+ 36: 36,
39
+ 37: 37,
40
+ 38: 38,
41
+ 39: 39,
42
+ 40: 40,
43
+ 41: 41,
44
+ 42: 42,
45
+ 43: 43,
46
+ 44: 44,
47
+ 45: 45,
48
+ 46: 46,
49
+ 47: 47,
50
+ 48: 48,
51
+ 49: 49,
52
+ 50: 50,
53
+ 51: 51,
54
+ 52: 52,
55
+ 53: 53,
56
+ 54: 54,
57
+ 55: 55,
58
+ 56: 56,
59
+ 57: 57,
60
+ 58: 58,
61
+ 59: 59,
62
+ 60: 60,
63
+ 61: 61,
64
+ 62: 62,
65
+ 63: 63,
66
+ 64: 64,
67
+ 65: 65,
68
+ 66: 66,
69
+ 67: 67,
70
+ 68: 68,
71
+ 69: 69,
72
+ 70: 70,
73
+ 71: 71,
74
+ 72: 72,
75
+ 73: 73,
76
+ 74: 74,
77
+ 75: 75,
78
+ 76: 76,
79
+ 77: 77,
80
+ 78: 78,
81
+ 79: 79,
82
+ 80: 80,
83
+ 81: 81,
84
+ 82: 82,
85
+ 83: 83,
86
+ 84: 84,
87
+ 85: 85,
88
+ 86: 86,
89
+ 87: 87,
90
+ 88: 88,
91
+ 89: 89,
92
+ 90: 90,
93
+ 91: 91,
94
+ 92: 92,
95
+ 93: 93,
96
+ 94: 94,
97
+ 95: 95,
98
+ 96: 96,
99
+ 97: 97,
100
+ 98: 98,
101
+ 99: 99,
102
+ 100: 100,
103
+ 101: 101,
104
+ 102: 102,
105
+ 103: 103,
106
+ 104: 104,
107
+ 105: 105,
108
+ 106: 106,
109
+ 107: 107,
110
+ 108: 108,
111
+ 109: 109,
112
+ 110: 110,
113
+ 111: 111,
114
+ 112: 112,
115
+ 113: 113,
116
+ 114: 114,
117
+ 115: 115,
118
+ 116: 116,
119
+ 117: 117,
120
+ 118: 118,
121
+ 119: 119,
122
+ 120: 120,
123
+ 121: 121,
124
+ 122: 122,
125
+ 123: 123,
126
+ 124: 124,
127
+ 125: 125,
128
+ 126: 126,
129
+ 127: 127,
130
+ 1027: 129,
131
+ 8225: 135,
132
+ 1046: 198,
133
+ 8222: 132,
134
+ 1047: 199,
135
+ 1168: 165,
136
+ 1048: 200,
137
+ 1113: 154,
138
+ 1049: 201,
139
+ 1045: 197,
140
+ 1050: 202,
141
+ 1028: 170,
142
+ 160: 160,
143
+ 1040: 192,
144
+ 1051: 203,
145
+ 164: 164,
146
+ 166: 166,
147
+ 167: 167,
148
+ 169: 169,
149
+ 171: 171,
150
+ 172: 172,
151
+ 173: 173,
152
+ 174: 174,
153
+ 1053: 205,
154
+ 176: 176,
155
+ 177: 177,
156
+ 1114: 156,
157
+ 181: 181,
158
+ 182: 182,
159
+ 183: 183,
160
+ 8221: 148,
161
+ 187: 187,
162
+ 1029: 189,
163
+ 1056: 208,
164
+ 1057: 209,
165
+ 1058: 210,
166
+ 8364: 136,
167
+ 1112: 188,
168
+ 1115: 158,
169
+ 1059: 211,
170
+ 1060: 212,
171
+ 1030: 178,
172
+ 1061: 213,
173
+ 1062: 214,
174
+ 1063: 215,
175
+ 1116: 157,
176
+ 1064: 216,
177
+ 1065: 217,
178
+ 1031: 175,
179
+ 1066: 218,
180
+ 1067: 219,
181
+ 1068: 220,
182
+ 1069: 221,
183
+ 1070: 222,
184
+ 1032: 163,
185
+ 8226: 149,
186
+ 1071: 223,
187
+ 1072: 224,
188
+ 8482: 153,
189
+ 1073: 225,
190
+ 8240: 137,
191
+ 1118: 162,
192
+ 1074: 226,
193
+ 1110: 179,
194
+ 8230: 133,
195
+ 1075: 227,
196
+ 1033: 138,
197
+ 1076: 228,
198
+ 1077: 229,
199
+ 8211: 150,
200
+ 1078: 230,
201
+ 1119: 159,
202
+ 1079: 231,
203
+ 1042: 194,
204
+ 1080: 232,
205
+ 1034: 140,
206
+ 1025: 168,
207
+ 1081: 233,
208
+ 1082: 234,
209
+ 8212: 151,
210
+ 1083: 235,
211
+ 1169: 180,
212
+ 1084: 236,
213
+ 1052: 204,
214
+ 1085: 237,
215
+ 1035: 142,
216
+ 1086: 238,
217
+ 1087: 239,
218
+ 1088: 240,
219
+ 1089: 241,
220
+ 1090: 242,
221
+ 1036: 141,
222
+ 1041: 193,
223
+ 1091: 243,
224
+ 1092: 244,
225
+ 8224: 134,
226
+ 1093: 245,
227
+ 8470: 185,
228
+ 1094: 246,
229
+ 1054: 206,
230
+ 1095: 247,
231
+ 1096: 248,
232
+ 8249: 139,
233
+ 1097: 249,
234
+ 1098: 250,
235
+ 1044: 196,
236
+ 1099: 251,
237
+ 1111: 191,
238
+ 1055: 207,
239
+ 1100: 252,
240
+ 1038: 161,
241
+ 8220: 147,
242
+ 1101: 253,
243
+ 8250: 155,
244
+ 1102: 254,
245
+ 8216: 145,
246
+ 1103: 255,
247
+ 1043: 195,
248
+ 1105: 184,
249
+ 1039: 143,
250
+ 1026: 128,
251
+ 1106: 144,
252
+ 8218: 130,
253
+ 1107: 131,
254
+ 8217: 146,
255
+ 1108: 186,
256
+ 1109: 190,
257
+ };
258
+ export function unicodeToWin1251(s) {
259
+ const L = [];
260
+ for (let i = 0; i < s.length; i++) {
261
+ // eslint-disable-next-line unicorn/prefer-code-point
262
+ const ord = s.charCodeAt(i);
263
+ if (!(ord in DMap))
264
+ throw new Error('Character ' + s.charAt(i) + " isn't supported by win1251!");
265
+ // eslint-disable-next-line unicorn/prefer-code-point
266
+ L.push(String.fromCharCode(DMap[ord]));
267
+ }
268
+ return L.join('');
269
+ }
package/file.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const getBase64FromFile: (file: File) => Promise<string>;
2
+ export declare const getTextFromFile: (file: File, encoding?: string) => Promise<string>;
3
+ //# sourceMappingURL=file.d.ts.map
package/file.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,SAAU,IAAI,oBAW3C,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,IAAI,aAAa,MAAM,oBAW5D,CAAC"}
package/file.js ADDED
@@ -0,0 +1,25 @@
1
+ /* eslint-disable sonarjs/no-base-to-string */
2
+ export const getBase64FromFile = (file) => {
3
+ return new Promise((resolve, reject) => {
4
+ const reader = new FileReader();
5
+ reader.readAsDataURL(file);
6
+ reader.onload = function () {
7
+ resolve(reader.result.toString());
8
+ };
9
+ reader.onerror = function (error) {
10
+ reject(error);
11
+ };
12
+ });
13
+ };
14
+ export const getTextFromFile = (file, encoding) => {
15
+ return new Promise((resolve, reject) => {
16
+ const reader = new FileReader();
17
+ reader.readAsText(file, encoding);
18
+ reader.onload = function () {
19
+ resolve(reader.result.toString());
20
+ };
21
+ reader.onerror = function (error) {
22
+ reject(error);
23
+ };
24
+ });
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "3.0.34",
3
+ "version": "3.0.35",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -93,6 +93,16 @@
93
93
  "default": "./device.js",
94
94
  "types": "./device.d.ts"
95
95
  },
96
+ "./encodings": {
97
+ "import": "./encodings.js",
98
+ "default": "./encodings.js",
99
+ "types": "./encodings.d.ts"
100
+ },
101
+ "./file": {
102
+ "import": "./file.js",
103
+ "default": "./file.js",
104
+ "types": "./file.d.ts"
105
+ },
96
106
  "./html": {
97
107
  "import": "./html.js",
98
108
  "default": "./html.js",
@@ -1 +1 @@
1
- {"version":3,"file":"type-guard.d.ts","sourceRoot":"","sources":["../src/type-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA4C1D,eAAO,MAAM,SAAS;oBALZ,OAAO,KAAG,KAAK,QAAK;yBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,aAAK;qBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;uBAApB,OAAO,KAAG,KAAK,WAAK;wBAApB,OAAO,KAAG,KAAK,eAAK;sBAApB,OAAO,KAAG,KAAK,WAAK;uBAApB,OAAO,KAAG,KAAK,eAAK;mBAApB,OAAO,KAAG,KAAK,UAAK;wBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;gBAGX,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,KAAG,KAAK,IAAI,CAAC;CAiB7D,CAAC"}
1
+ {"version":3,"file":"type-guard.d.ts","sourceRoot":"","sources":["../src/type-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAuD1D,eAAO,MAAM,SAAS;oBALZ,OAAO,KAAG,KAAK,QAAK;yBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,aAAK;qBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;uBAApB,OAAO,KAAG,KAAK,WAAK;wBAApB,OAAO,KAAG,KAAK,eAAK;sBAApB,OAAO,KAAG,KAAK,WAAK;uBAApB,OAAO,KAAG,KAAK,eAAK;mBAApB,OAAO,KAAG,KAAK,UAAK;wBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;gBAGX,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,KAAG,KAAK,IAAI,CAAC;CAiB7D,CAAC"}
package/type-guard.js CHANGED
@@ -1,46 +1,59 @@
1
- // Based on https://gist.github.com/jonbretman/7259628
1
+ var Type;
2
+ (function (Type) {
3
+ Type["Null"] = "null";
4
+ Type["Undefined"] = "undefined";
5
+ Type["NaN"] = "nan";
6
+ Type["Object"] = "[object Object]";
7
+ Type["Array"] = "[object Array]";
8
+ Type["String"] = "[object String]";
9
+ Type["Number"] = "[object Number]";
10
+ Type["Boolean"] = "[object Boolean]";
11
+ Type["Function"] = "[object Function]";
12
+ Type["RegExp"] = "[object RegExp]";
13
+ Type["Symbol"] = "[object Symbol]";
14
+ Type["Infinite"] = "infinite";
15
+ Type["Element"] = "element";
16
+ })(Type || (Type = {}));
2
17
  function getType(value) {
3
- // handle corner cases for old IE and PhantomJS
4
18
  if (value === undefined) {
5
- return 'undefined';
19
+ return Type.Undefined;
6
20
  }
7
21
  if (value === null) {
8
- return 'null';
22
+ return Type.Null;
9
23
  }
10
24
  // handle DOM elements
11
25
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
26
  // @ts-ignore
13
27
  if (value && (value.nodeType === 1 || value.nodeType === 9)) {
14
- return 'element';
28
+ return Type.Element;
15
29
  }
16
- const toStringResult = Object.prototype.toString.call(value);
17
- const type = toStringResult.slice('[object '.length, -1).toLowerCase();
30
+ const stringifiedValue = Object.prototype.toString.call(value);
18
31
  // handle NaN and Infinity
19
- if (type === 'number') {
32
+ if (stringifiedValue === Type.Number) {
20
33
  if (Number.isNaN(value)) {
21
- return 'nan';
34
+ return Type.NaN;
22
35
  }
23
36
  if (!Number.isFinite(value)) {
24
- return 'infinity';
37
+ return Type.Infinite;
25
38
  }
26
39
  }
27
- return type;
40
+ return stringifiedValue;
28
41
  }
29
42
  const createTypeGuard = (type) => (value) => getType(value) === type;
30
43
  const isDefined = (value) => value != null;
31
44
  export const typeGuard = {
32
- isNull: createTypeGuard('null'),
33
- isUndefined: createTypeGuard('undefined'),
34
- isObject: createTypeGuard('object'),
35
- isArray: createTypeGuard('array'),
36
- isString: createTypeGuard('string'),
37
- isNumber: createTypeGuard('number'),
38
- isBoolean: createTypeGuard('boolean'),
39
- isFunction: createTypeGuard('function'),
40
- isRegExp: createTypeGuard('regexp'),
41
- isElement: createTypeGuard('element'),
42
- isNaN: createTypeGuard('nan'),
43
- isInfinite: createTypeGuard('infinite'),
44
- isSymbol: createTypeGuard('symbol'),
45
+ isNull: createTypeGuard(Type.Null),
46
+ isUndefined: createTypeGuard(Type.Undefined),
47
+ isObject: createTypeGuard(Type.Object),
48
+ isArray: createTypeGuard(Type.Array),
49
+ isString: createTypeGuard(Type.String),
50
+ isNumber: createTypeGuard(Type.Number),
51
+ isBoolean: createTypeGuard(Type.Boolean),
52
+ isFunction: createTypeGuard(Type.Function),
53
+ isRegExp: createTypeGuard(Type.RegExp),
54
+ isElement: createTypeGuard(Type.Element),
55
+ isNaN: createTypeGuard(Type.NaN),
56
+ isInfinite: createTypeGuard(Type.Infinite),
57
+ isSymbol: createTypeGuard(Type.Symbol),
45
58
  isDefined,
46
59
  };