79 lines
2.4 KiB
Plaintext
Executable File
79 lines
2.4 KiB
Plaintext
Executable File
/**
|
|
* Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue
|
|
* @param x number
|
|
*/
|
|
export function getMagnitude(x) {
|
|
// Cannot count string length via Number.toString because it may use scientific notation
|
|
// for very small or very large numbers.
|
|
return Math.floor(Math.log(x) * Math.LOG10E);
|
|
}
|
|
export function repeat(s, times) {
|
|
if (typeof s.repeat === 'function') {
|
|
return s.repeat(times);
|
|
}
|
|
var arr = new Array(times);
|
|
for (var i = 0; i < arr.length; i++) {
|
|
arr[i] = s;
|
|
}
|
|
return arr.join('');
|
|
}
|
|
export function setInternalSlot(map, pl, field, value) {
|
|
if (!map.get(pl)) {
|
|
map.set(pl, Object.create(null));
|
|
}
|
|
var slots = map.get(pl);
|
|
slots[field] = value;
|
|
}
|
|
export function setMultiInternalSlots(map, pl, props) {
|
|
for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
|
|
var k = _a[_i];
|
|
setInternalSlot(map, pl, k, props[k]);
|
|
}
|
|
}
|
|
export function getInternalSlot(map, pl, field) {
|
|
return getMultiInternalSlots(map, pl, field)[field];
|
|
}
|
|
export function getMultiInternalSlots(map, pl) {
|
|
var fields = [];
|
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
fields[_i - 2] = arguments[_i];
|
|
}
|
|
var slots = map.get(pl);
|
|
if (!slots) {
|
|
throw new TypeError("".concat(pl, " InternalSlot has not been initialized"));
|
|
}
|
|
return fields.reduce(function (all, f) {
|
|
all[f] = slots[f];
|
|
return all;
|
|
}, Object.create(null));
|
|
}
|
|
export function isLiteralPart(patternPart) {
|
|
return patternPart.type === 'literal';
|
|
}
|
|
/*
|
|
17 ECMAScript Standard Built-in Objects:
|
|
Every built-in Function object, including constructors, that is not
|
|
identified as an anonymous function has a name property whose value
|
|
is a String.
|
|
|
|
Unless otherwise specified, the name property of a built-in Function
|
|
object, if it exists, has the attributes { [[Writable]]: false,
|
|
[[Enumerable]]: false, [[Configurable]]: true }.
|
|
*/
|
|
export function defineProperty(target, name, _a) {
|
|
var value = _a.value;
|
|
Object.defineProperty(target, name, {
|
|
configurable: true,
|
|
enumerable: false,
|
|
writable: true,
|
|
value: value,
|
|
});
|
|
}
|
|
export var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
|
|
export function invariant(condition, message, Err) {
|
|
if (Err === void 0) { Err = Error; }
|
|
if (!condition) {
|
|
throw new Err(message);
|
|
}
|
|
}
|