File size: 14,554 Bytes
96af7c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
import { safeApply } from './apply.js';
const SArray = typeof Array !== 'undefined' ? Array : undefined;
export { SArray as Array };
const SBigInt = typeof BigInt !== 'undefined' ? BigInt : undefined;
export { SBigInt as BigInt };
const SBigInt64Array = typeof BigInt64Array !== 'undefined' ? BigInt64Array : undefined;
export { SBigInt64Array as BigInt64Array };
const SBigUint64Array = typeof BigUint64Array !== 'undefined' ? BigUint64Array : undefined;
export { SBigUint64Array as BigUint64Array };
const SBoolean = typeof Boolean !== 'undefined' ? Boolean : undefined;
export { SBoolean as Boolean };
const SDate = typeof Date !== 'undefined' ? Date : undefined;
export { SDate as Date };
const SError = typeof Error !== 'undefined' ? Error : undefined;
export { SError as Error };
const SFloat32Array = typeof Float32Array !== 'undefined' ? Float32Array : undefined;
export { SFloat32Array as Float32Array };
const SFloat64Array = typeof Float64Array !== 'undefined' ? Float64Array : undefined;
export { SFloat64Array as Float64Array };
const SInt8Array = typeof Int8Array !== 'undefined' ? Int8Array : undefined;
export { SInt8Array as Int8Array };
const SInt16Array = typeof Int16Array !== 'undefined' ? Int16Array : undefined;
export { SInt16Array as Int16Array };
const SInt32Array = typeof Int32Array !== 'undefined' ? Int32Array : undefined;
export { SInt32Array as Int32Array };
const SNumber = typeof Number !== 'undefined' ? Number : undefined;
export { SNumber as Number };
const SString = typeof String !== 'undefined' ? String : undefined;
export { SString as String };
const SSet = typeof Set !== 'undefined' ? Set : undefined;
export { SSet as Set };
const SUint8Array = typeof Uint8Array !== 'undefined' ? Uint8Array : undefined;
export { SUint8Array as Uint8Array };
const SUint8ClampedArray = typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : undefined;
export { SUint8ClampedArray as Uint8ClampedArray };
const SUint16Array = typeof Uint16Array !== 'undefined' ? Uint16Array : undefined;
export { SUint16Array as Uint16Array };
const SUint32Array = typeof Uint32Array !== 'undefined' ? Uint32Array : undefined;
export { SUint32Array as Uint32Array };
const SencodeURIComponent = typeof encodeURIComponent !== 'undefined' ? encodeURIComponent : undefined;
export { SencodeURIComponent as encodeURIComponent };
const SMap = Map;
export { SMap as Map };
const SSymbol = Symbol;
export { SSymbol as Symbol };
const untouchedForEach = Array.prototype.forEach;
const untouchedIndexOf = Array.prototype.indexOf;
const untouchedJoin = Array.prototype.join;
const untouchedMap = Array.prototype.map;
const untouchedFilter = Array.prototype.filter;
const untouchedPush = Array.prototype.push;
const untouchedPop = Array.prototype.pop;
const untouchedSplice = Array.prototype.splice;
const untouchedSlice = Array.prototype.slice;
const untouchedSort = Array.prototype.sort;
const untouchedEvery = Array.prototype.every;
function extractForEach(instance) {
try {
return instance.forEach;
}
catch (err) {
return undefined;
}
}
function extractIndexOf(instance) {
try {
return instance.indexOf;
}
catch (err) {
return undefined;
}
}
function extractJoin(instance) {
try {
return instance.join;
}
catch (err) {
return undefined;
}
}
function extractMap(instance) {
try {
return instance.map;
}
catch (err) {
return undefined;
}
}
function extractFilter(instance) {
try {
return instance.filter;
}
catch (err) {
return undefined;
}
}
function extractPush(instance) {
try {
return instance.push;
}
catch (err) {
return undefined;
}
}
function extractPop(instance) {
try {
return instance.pop;
}
catch (err) {
return undefined;
}
}
function extractSplice(instance) {
try {
return instance.splice;
}
catch (err) {
return undefined;
}
}
function extractSlice(instance) {
try {
return instance.slice;
}
catch (err) {
return undefined;
}
}
function extractSort(instance) {
try {
return instance.sort;
}
catch (err) {
return undefined;
}
}
function extractEvery(instance) {
try {
return instance.every;
}
catch (err) {
return undefined;
}
}
export function safeForEach(instance, fn) {
if (extractForEach(instance) === untouchedForEach) {
return instance.forEach(fn);
}
return safeApply(untouchedForEach, instance, [fn]);
}
export function safeIndexOf(instance, ...args) {
if (extractIndexOf(instance) === untouchedIndexOf) {
return instance.indexOf(...args);
}
return safeApply(untouchedIndexOf, instance, args);
}
export function safeJoin(instance, ...args) {
if (extractJoin(instance) === untouchedJoin) {
return instance.join(...args);
}
return safeApply(untouchedJoin, instance, args);
}
export function safeMap(instance, fn) {
if (extractMap(instance) === untouchedMap) {
return instance.map(fn);
}
return safeApply(untouchedMap, instance, [fn]);
}
export function safeFilter(instance, predicate) {
if (extractFilter(instance) === untouchedFilter) {
return instance.filter(predicate);
}
return safeApply(untouchedFilter, instance, [predicate]);
}
export function safePush(instance, ...args) {
if (extractPush(instance) === untouchedPush) {
return instance.push(...args);
}
return safeApply(untouchedPush, instance, args);
}
export function safePop(instance) {
if (extractPop(instance) === untouchedPop) {
return instance.pop();
}
return safeApply(untouchedPop, instance, []);
}
export function safeSplice(instance, ...args) {
if (extractSplice(instance) === untouchedSplice) {
return instance.splice(...args);
}
return safeApply(untouchedSplice, instance, args);
}
export function safeSlice(instance, ...args) {
if (extractSlice(instance) === untouchedSlice) {
return instance.slice(...args);
}
return safeApply(untouchedSlice, instance, args);
}
export function safeSort(instance, ...args) {
if (extractSort(instance) === untouchedSort) {
return instance.sort(...args);
}
return safeApply(untouchedSort, instance, args);
}
export function safeEvery(instance, ...args) {
if (extractEvery(instance) === untouchedEvery) {
return instance.every(...args);
}
return safeApply(untouchedEvery, instance, args);
}
const untouchedGetTime = Date.prototype.getTime;
const untouchedToISOString = Date.prototype.toISOString;
function extractGetTime(instance) {
try {
return instance.getTime;
}
catch (err) {
return undefined;
}
}
function extractToISOString(instance) {
try {
return instance.toISOString;
}
catch (err) {
return undefined;
}
}
export function safeGetTime(instance) {
if (extractGetTime(instance) === untouchedGetTime) {
return instance.getTime();
}
return safeApply(untouchedGetTime, instance, []);
}
export function safeToISOString(instance) {
if (extractToISOString(instance) === untouchedToISOString) {
return instance.toISOString();
}
return safeApply(untouchedToISOString, instance, []);
}
const untouchedAdd = Set.prototype.add;
const untouchedHas = Set.prototype.has;
function extractAdd(instance) {
try {
return instance.add;
}
catch (err) {
return undefined;
}
}
function extractHas(instance) {
try {
return instance.has;
}
catch (err) {
return undefined;
}
}
export function safeAdd(instance, value) {
if (extractAdd(instance) === untouchedAdd) {
return instance.add(value);
}
return safeApply(untouchedAdd, instance, [value]);
}
export function safeHas(instance, value) {
if (extractHas(instance) === untouchedHas) {
return instance.has(value);
}
return safeApply(untouchedHas, instance, [value]);
}
const untouchedSet = WeakMap.prototype.set;
const untouchedGet = WeakMap.prototype.get;
function extractSet(instance) {
try {
return instance.set;
}
catch (err) {
return undefined;
}
}
function extractGet(instance) {
try {
return instance.get;
}
catch (err) {
return undefined;
}
}
export function safeSet(instance, key, value) {
if (extractSet(instance) === untouchedSet) {
return instance.set(key, value);
}
return safeApply(untouchedSet, instance, [key, value]);
}
export function safeGet(instance, key) {
if (extractGet(instance) === untouchedGet) {
return instance.get(key);
}
return safeApply(untouchedGet, instance, [key]);
}
const untouchedMapSet = Map.prototype.set;
const untouchedMapGet = Map.prototype.get;
function extractMapSet(instance) {
try {
return instance.set;
}
catch (err) {
return undefined;
}
}
function extractMapGet(instance) {
try {
return instance.get;
}
catch (err) {
return undefined;
}
}
export function safeMapSet(instance, key, value) {
if (extractMapSet(instance) === untouchedMapSet) {
return instance.set(key, value);
}
return safeApply(untouchedMapSet, instance, [key, value]);
}
export function safeMapGet(instance, key) {
if (extractMapGet(instance) === untouchedMapGet) {
return instance.get(key);
}
return safeApply(untouchedMapGet, instance, [key]);
}
const untouchedSplit = String.prototype.split;
const untouchedStartsWith = String.prototype.startsWith;
const untouchedEndsWith = String.prototype.endsWith;
const untouchedSubstring = String.prototype.substring;
const untouchedToLowerCase = String.prototype.toLowerCase;
const untouchedToUpperCase = String.prototype.toUpperCase;
const untouchedPadStart = String.prototype.padStart;
const untouchedCharCodeAt = String.prototype.charCodeAt;
const untouchedNormalize = String.prototype.normalize;
const untouchedReplace = String.prototype.replace;
function extractSplit(instance) {
try {
return instance.split;
}
catch (err) {
return undefined;
}
}
function extractStartsWith(instance) {
try {
return instance.startsWith;
}
catch (err) {
return undefined;
}
}
function extractEndsWith(instance) {
try {
return instance.endsWith;
}
catch (err) {
return undefined;
}
}
function extractSubstring(instance) {
try {
return instance.substring;
}
catch (err) {
return undefined;
}
}
function extractToLowerCase(instance) {
try {
return instance.toLowerCase;
}
catch (err) {
return undefined;
}
}
function extractToUpperCase(instance) {
try {
return instance.toUpperCase;
}
catch (err) {
return undefined;
}
}
function extractPadStart(instance) {
try {
return instance.padStart;
}
catch (err) {
return undefined;
}
}
function extractCharCodeAt(instance) {
try {
return instance.charCodeAt;
}
catch (err) {
return undefined;
}
}
function extractNormalize(instance) {
try {
return instance.normalize;
}
catch (err) {
return undefined;
}
}
function extractReplace(instance) {
try {
return instance.replace;
}
catch (err) {
return undefined;
}
}
export function safeSplit(instance, ...args) {
if (extractSplit(instance) === untouchedSplit) {
return instance.split(...args);
}
return safeApply(untouchedSplit, instance, args);
}
export function safeStartsWith(instance, ...args) {
if (extractStartsWith(instance) === untouchedStartsWith) {
return instance.startsWith(...args);
}
return safeApply(untouchedStartsWith, instance, args);
}
export function safeEndsWith(instance, ...args) {
if (extractEndsWith(instance) === untouchedEndsWith) {
return instance.endsWith(...args);
}
return safeApply(untouchedEndsWith, instance, args);
}
export function safeSubstring(instance, ...args) {
if (extractSubstring(instance) === untouchedSubstring) {
return instance.substring(...args);
}
return safeApply(untouchedSubstring, instance, args);
}
export function safeToLowerCase(instance) {
if (extractToLowerCase(instance) === untouchedToLowerCase) {
return instance.toLowerCase();
}
return safeApply(untouchedToLowerCase, instance, []);
}
export function safeToUpperCase(instance) {
if (extractToUpperCase(instance) === untouchedToUpperCase) {
return instance.toUpperCase();
}
return safeApply(untouchedToUpperCase, instance, []);
}
export function safePadStart(instance, ...args) {
if (extractPadStart(instance) === untouchedPadStart) {
return instance.padStart(...args);
}
return safeApply(untouchedPadStart, instance, args);
}
export function safeCharCodeAt(instance, index) {
if (extractCharCodeAt(instance) === untouchedCharCodeAt) {
return instance.charCodeAt(index);
}
return safeApply(untouchedCharCodeAt, instance, [index]);
}
export function safeNormalize(instance, form) {
if (extractNormalize(instance) === untouchedNormalize) {
return instance.normalize(form);
}
return safeApply(untouchedNormalize, instance, [form]);
}
export function safeReplace(instance, pattern, replacement) {
if (extractReplace(instance) === untouchedReplace) {
return instance.replace(pattern, replacement);
}
return safeApply(untouchedReplace, instance, [pattern, replacement]);
}
const untouchedNumberToString = Number.prototype.toString;
function extractNumberToString(instance) {
try {
return instance.toString;
}
catch (err) {
return undefined;
}
}
export function safeNumberToString(instance, ...args) {
if (extractNumberToString(instance) === untouchedNumberToString) {
return instance.toString(...args);
}
return safeApply(untouchedNumberToString, instance, args);
}
const untouchedHasOwnProperty = Object.prototype.hasOwnProperty;
const untouchedToString = Object.prototype.toString;
export function safeHasOwnProperty(instance, v) {
return safeApply(untouchedHasOwnProperty, instance, [v]);
}
export function safeToString(instance) {
return safeApply(untouchedToString, instance, []);
}
|