lib0 0.2.52 → 0.2.53
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/README.md +3 -0
- package/dist/{broadcastchannel-7655b66f.cjs → broadcastchannel-a5969a44.cjs} +2 -2
- package/dist/{broadcastchannel-7655b66f.cjs.map → broadcastchannel-a5969a44.cjs.map} +1 -1
- package/dist/broadcastchannel.cjs +6 -3
- package/dist/broadcastchannel.cjs.map +1 -1
- package/dist/{buffer-d3ba308b.cjs → buffer-9c449d1d.cjs} +3 -3
- package/dist/buffer-9c449d1d.cjs.map +1 -0
- package/dist/buffer.cjs +5 -2
- package/dist/buffer.cjs.map +1 -1
- package/dist/cache.cjs +1 -1
- package/dist/component.cjs +2 -2
- package/dist/decoding.cjs +5 -2
- package/dist/decoding.cjs.map +1 -1
- package/dist/{diff-2593547b.cjs → diff-642271b1.cjs} +2 -2
- package/dist/{diff-2593547b.cjs.map → diff-642271b1.cjs.map} +1 -1
- package/dist/diff.cjs +2 -2
- package/dist/encoding.cjs +5 -2
- package/dist/encoding.cjs.map +1 -1
- package/dist/{environment-60b83194.cjs → environment-3c81ab2f.cjs} +36 -13
- package/dist/environment-3c81ab2f.cjs.map +1 -0
- package/dist/environment.cjs +5 -1
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.ts +1 -0
- package/dist/environment.d.ts.map +1 -1
- package/dist/{function-e4045b1d.cjs → function-3410854f.cjs} +14 -2
- package/dist/{function-e4045b1d.cjs.map → function-3410854f.cjs.map} +1 -1
- package/dist/function.cjs +2 -1
- package/dist/function.cjs.map +1 -1
- package/dist/function.d.ts +1 -0
- package/dist/function.d.ts.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/list.cjs +1 -1
- package/dist/{logging-0a4d8595.cjs → logging-a2dc7e43.cjs} +131 -34
- package/dist/logging-a2dc7e43.cjs.map +1 -0
- package/dist/logging.cjs +3 -3
- package/dist/logging.d.ts.map +1 -1
- package/dist/{prng-76a2f4be.cjs → prng-c71ea8ea.cjs} +2 -2
- package/dist/{prng-76a2f4be.cjs.map → prng-c71ea8ea.cjs.map} +1 -1
- package/dist/prng.cjs +6 -3
- package/dist/prng.cjs.map +1 -1
- package/dist/testing.cjs +6 -6
- package/encoding.js +1 -1
- package/environment.d.ts +1 -0
- package/environment.d.ts.map +1 -1
- package/environment.js +32 -11
- package/function.d.ts +1 -0
- package/function.d.ts.map +1 -1
- package/function.js +10 -0
- package/logging.d.ts.map +1 -1
- package/logging.js +128 -31
- package/package.json +1 -1
- package/dist/buffer-d3ba308b.cjs.map +0 -1
- package/dist/environment-60b83194.cjs.map +0 -1
- package/dist/logging-0a4d8595.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prng-76a2f4be.cjs","sources":["../prng/Xorshift32.js","../prng/Xoroshiro128plus.js","../prng.js"],"sourcesContent":["/**\n * @module prng\n */\n\nimport * as binary from '../binary.js'\n\n/**\n * Xorshift32 is a very simple but elegang PRNG with a period of `2^32-1`.\n */\nexport class Xorshift32 {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n /**\n * @type {number}\n */\n this._state = seed\n }\n\n /**\n * Generate a random signed integer.\n *\n * @return {Number} A 32 bit signed integer.\n */\n next () {\n let x = this._state\n x ^= x << 13\n x ^= x >> 17\n x ^= x << 5\n this._state = x\n return (x >>> 0) / (binary.BITS32 + 1)\n }\n}\n","/**\n * @module prng\n */\n\nimport { Xorshift32 } from './Xorshift32.js'\nimport * as binary from '../binary.js'\n\n/**\n * This is a variant of xoroshiro128plus - the fastest full-period generator passing BigCrush without systematic failures.\n *\n * This implementation follows the idea of the original xoroshiro128plus implementation,\n * but is optimized for the JavaScript runtime. I.e.\n * * The operations are performed on 32bit integers (the original implementation works with 64bit values).\n * * The initial 128bit state is computed based on a 32bit seed and Xorshift32.\n * * This implementation returns two 32bit values based on the 64bit value that is computed by xoroshiro128plus.\n * Caution: The last addition step works slightly different than in the original implementation - the add carry of the\n * first 32bit addition is not carried over to the last 32bit.\n *\n * [Reference implementation](http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c)\n */\nexport class Xoroshiro128plus {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n // This is a variant of Xoroshiro128plus to fill the initial state\n const xorshift32 = new Xorshift32(seed)\n this.state = new Uint32Array(4)\n for (let i = 0; i < 4; i++) {\n this.state[i] = xorshift32.next() * binary.BITS32\n }\n this._fresh = true\n }\n\n /**\n * @return {number} Float/Double in [0,1)\n */\n next () {\n const state = this.state\n if (this._fresh) {\n this._fresh = false\n return ((state[0] + state[2]) >>> 0) / (binary.BITS32 + 1)\n } else {\n this._fresh = true\n const s0 = state[0]\n const s1 = state[1]\n const s2 = state[2] ^ s0\n const s3 = state[3] ^ s1\n // function js_rotl (x, k) {\n // k = k - 32\n // const x1 = x[0]\n // const x2 = x[1]\n // x[0] = x2 << k | x1 >>> (32 - k)\n // x[1] = x1 << k | x2 >>> (32 - k)\n // }\n // rotl(s0, 55) // k = 23 = 55 - 32; j = 9 = 32 - 23\n state[0] = (s1 << 23 | s0 >>> 9) ^ s2 ^ (s2 << 14 | s3 >>> 18)\n state[1] = (s0 << 23 | s1 >>> 9) ^ s3 ^ (s3 << 14)\n // rol(s1, 36) // k = 4 = 36 - 32; j = 23 = 32 - 9\n state[2] = s3 << 4 | s2 >>> 28\n state[3] = s2 << 4 | s3 >>> 28\n return (((state[1] + state[3]) >>> 0) / (binary.BITS32 + 1))\n }\n }\n}\n\n/*\n// Reference implementation\n// Source: http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c\n// By David Blackman and Sebastiano Vigna\n// Who published the reference implementation under Public Domain (CC0)\n\n#include <stdint.h>\n#include <stdio.h>\n\nuint64_t s[2];\n\nstatic inline uint64_t rotl(const uint64_t x, int k) {\n return (x << k) | (x >> (64 - k));\n}\n\nuint64_t next(void) {\n const uint64_t s0 = s[0];\n uint64_t s1 = s[1];\n s1 ^= s0;\n s[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14); // a, b\n s[1] = rotl(s1, 36); // c\n return (s[0] + s[1]) & 0xFFFFFFFF;\n}\n\nint main(void)\n{\n int i;\n s[0] = 1111 | (1337ul << 32);\n s[1] = 1234 | (9999ul << 32);\n\n printf(\"1000 outputs of genrand_int31()\\n\");\n for (i=0; i<100; i++) {\n printf(\"%10lu \", i);\n printf(\"%10lu \", next());\n printf(\"- %10lu \", s[0] >> 32);\n printf(\"%10lu \", (s[0] << 32) >> 32);\n printf(\"%10lu \", s[1] >> 32);\n printf(\"%10lu \", (s[1] << 32) >> 32);\n printf(\"\\n\");\n // if (i%5==4) printf(\"\\n\");\n }\n return 0;\n}\n*/\n","/**\n * Fast Pseudo Random Number Generators.\n *\n * Given a seed a PRNG generates a sequence of numbers that cannot be reasonably predicted.\n * Two PRNGs must generate the same random sequence of numbers if given the same seed.\n *\n * @module prng\n */\n\nimport * as binary from './binary.js'\nimport { fromCharCode, fromCodePoint } from './string.js'\nimport * as math from './math.js'\nimport { Xoroshiro128plus } from './prng/Xoroshiro128plus.js'\nimport * as buffer from './buffer.js'\n\n/**\n * Description of the function\n * @callback generatorNext\n * @return {number} A random float in the cange of [0,1)\n */\n\n/**\n * A random type generator.\n *\n * @typedef {Object} PRNG\n * @property {generatorNext} next Generate new number\n */\n\nexport const DefaultPRNG = Xoroshiro128plus\n\n/**\n * Create a Xoroshiro128plus Pseudo-Random-Number-Generator.\n * This is the fastest full-period generator passing BigCrush without systematic failures.\n * But there are more PRNGs available in ./PRNG/.\n *\n * @param {number} seed A positive 32bit integer. Do not use negative numbers.\n * @return {PRNG}\n */\nexport const create = seed => new DefaultPRNG(seed)\n\n/**\n * Generates a single random bool.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Boolean} A random boolean\n */\nexport const bool = gen => (gen.next() >= 0.5)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int53 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint53 = (gen, min, max) => math.abs(int53(gen, min, max))\n\n/**\n * Generates a random integer with 32 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int32 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint32 = (gen, min, max) => int32(gen, min, max) >>> 0\n\n/**\n * @deprecated\n * Optimized version of prng.int32. It has the same precision as prng.int32, but should be preferred when\n * openaring on smaller ranges.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive). The max inclusive number is `binary.BITS31-1`\n * @return {Number} A random integer on [min, max]\n */\nexport const int31 = (gen, min, max) => int32(gen, min, max)\n\n/**\n * Generates a random real on [0, 1) with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Number} A random real number on [0, 1).\n */\nexport const real53 = gen => gen.next() // (((gen.next() >>> 5) * binary.BIT26) + (gen.next() >>> 6)) / MAX_SAFE_INTEGER\n\n/**\n * Generates a random character from char code 32 - 126. I.e. Characters, Numbers, special characters, and Space:\n *\n * @param {PRNG} gen A random number generator.\n * @return {string}\n *\n * (Space)!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`abcdefghijklmnopqrstuvwxyz{|}~\n */\nexport const char = gen => fromCharCode(int31(gen, 32, 126))\n\n/**\n * @param {PRNG} gen\n * @return {string} A single letter (a-z)\n */\nexport const letter = gen => fromCharCode(int31(gen, 97, 122))\n\n/**\n * @param {PRNG} gen\n * @param {number} [minLen=0]\n * @param {number} [maxLen=20]\n * @return {string} A random word (0-20 characters) without spaces consisting of letters (a-z)\n */\nexport const word = (gen, minLen = 0, maxLen = 20) => {\n const len = int31(gen, minLen, maxLen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += letter(gen)\n }\n return str\n}\n\n/**\n * TODO: this function produces invalid runes. Does not cover all of utf16!!\n *\n * @param {PRNG} gen\n * @return {string}\n */\nexport const utf16Rune = gen => {\n const codepoint = int31(gen, 0, 256)\n return fromCodePoint(codepoint)\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} [maxlen = 20]\n */\nexport const utf16String = (gen, maxlen = 20) => {\n const len = int31(gen, 0, maxlen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += utf16Rune(gen)\n }\n return str\n}\n\n/**\n * Returns one element of a given array.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Array<T>} array Non empty Array of possible values.\n * @return {T} One of the values of the supplied Array.\n * @template T\n */\nexport const oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)]\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint8Array}\n */\nexport const uint8Array = (gen, len) => {\n const buf = buffer.createUint8ArrayFromLen(len)\n for (let i = 0; i < buf.length; i++) {\n buf[i] = int32(gen, 0, binary.BITS8)\n }\n return buf\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint16Array}\n */\nexport const uint16Array = (gen, len) => new Uint16Array(uint8Array(gen, len * 2).buffer)\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint32Array}\n */\nexport const uint32Array = (gen, len) => new Uint32Array(uint8Array(gen, len * 4).buffer)\n"],"names":["binary.BITS32","math.floor","math.abs","fromCharCode","fromCodePoint","buffer.createUint8ArrayFromLen","binary.BITS8"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGA;AACA;AACA;AACA;AACO,MAAM,UAAU,CAAC;AACxB;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,MAAM,GAAG,KAAI;AACtB,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,GAAG;AACV,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,OAAM;AACvB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAE;AAChB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAE;AAChB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAC;AACf,IAAI,IAAI,CAAC,MAAM,GAAG,EAAC;AACnB,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,KAAKA,aAAa,GAAG,CAAC,CAAC;AAC1C,GAAG;AACH;;AClCA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gBAAgB,CAAC;AAC9B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA,IAAI,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,EAAC;AAC3C,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,EAAC;AACnC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AAChC,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG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,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAKA,aAAa,GAAG,CAAC,CAAC,CAAC;AAClE,KAAK;AACL,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,iBAAgB;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,EAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,EAAC;AACtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKD,UAA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AK,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,EAAC;AACzF;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"prng-c71ea8ea.cjs","sources":["../prng/Xorshift32.js","../prng/Xoroshiro128plus.js","../prng.js"],"sourcesContent":["/**\n * @module prng\n */\n\nimport * as binary from '../binary.js'\n\n/**\n * Xorshift32 is a very simple but elegang PRNG with a period of `2^32-1`.\n */\nexport class Xorshift32 {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n /**\n * @type {number}\n */\n this._state = seed\n }\n\n /**\n * Generate a random signed integer.\n *\n * @return {Number} A 32 bit signed integer.\n */\n next () {\n let x = this._state\n x ^= x << 13\n x ^= x >> 17\n x ^= x << 5\n this._state = x\n return (x >>> 0) / (binary.BITS32 + 1)\n }\n}\n","/**\n * @module prng\n */\n\nimport { Xorshift32 } from './Xorshift32.js'\nimport * as binary from '../binary.js'\n\n/**\n * This is a variant of xoroshiro128plus - the fastest full-period generator passing BigCrush without systematic failures.\n *\n * This implementation follows the idea of the original xoroshiro128plus implementation,\n * but is optimized for the JavaScript runtime. I.e.\n * * The operations are performed on 32bit integers (the original implementation works with 64bit values).\n * * The initial 128bit state is computed based on a 32bit seed and Xorshift32.\n * * This implementation returns two 32bit values based on the 64bit value that is computed by xoroshiro128plus.\n * Caution: The last addition step works slightly different than in the original implementation - the add carry of the\n * first 32bit addition is not carried over to the last 32bit.\n *\n * [Reference implementation](http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c)\n */\nexport class Xoroshiro128plus {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n // This is a variant of Xoroshiro128plus to fill the initial state\n const xorshift32 = new Xorshift32(seed)\n this.state = new Uint32Array(4)\n for (let i = 0; i < 4; i++) {\n this.state[i] = xorshift32.next() * binary.BITS32\n }\n this._fresh = true\n }\n\n /**\n * @return {number} Float/Double in [0,1)\n */\n next () {\n const state = this.state\n if (this._fresh) {\n this._fresh = false\n return ((state[0] + state[2]) >>> 0) / (binary.BITS32 + 1)\n } else {\n this._fresh = true\n const s0 = state[0]\n const s1 = state[1]\n const s2 = state[2] ^ s0\n const s3 = state[3] ^ s1\n // function js_rotl (x, k) {\n // k = k - 32\n // const x1 = x[0]\n // const x2 = x[1]\n // x[0] = x2 << k | x1 >>> (32 - k)\n // x[1] = x1 << k | x2 >>> (32 - k)\n // }\n // rotl(s0, 55) // k = 23 = 55 - 32; j = 9 = 32 - 23\n state[0] = (s1 << 23 | s0 >>> 9) ^ s2 ^ (s2 << 14 | s3 >>> 18)\n state[1] = (s0 << 23 | s1 >>> 9) ^ s3 ^ (s3 << 14)\n // rol(s1, 36) // k = 4 = 36 - 32; j = 23 = 32 - 9\n state[2] = s3 << 4 | s2 >>> 28\n state[3] = s2 << 4 | s3 >>> 28\n return (((state[1] + state[3]) >>> 0) / (binary.BITS32 + 1))\n }\n }\n}\n\n/*\n// Reference implementation\n// Source: http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c\n// By David Blackman and Sebastiano Vigna\n// Who published the reference implementation under Public Domain (CC0)\n\n#include <stdint.h>\n#include <stdio.h>\n\nuint64_t s[2];\n\nstatic inline uint64_t rotl(const uint64_t x, int k) {\n return (x << k) | (x >> (64 - k));\n}\n\nuint64_t next(void) {\n const uint64_t s0 = s[0];\n uint64_t s1 = s[1];\n s1 ^= s0;\n s[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14); // a, b\n s[1] = rotl(s1, 36); // c\n return (s[0] + s[1]) & 0xFFFFFFFF;\n}\n\nint main(void)\n{\n int i;\n s[0] = 1111 | (1337ul << 32);\n s[1] = 1234 | (9999ul << 32);\n\n printf(\"1000 outputs of genrand_int31()\\n\");\n for (i=0; i<100; i++) {\n printf(\"%10lu \", i);\n printf(\"%10lu \", next());\n printf(\"- %10lu \", s[0] >> 32);\n printf(\"%10lu \", (s[0] << 32) >> 32);\n printf(\"%10lu \", s[1] >> 32);\n printf(\"%10lu \", (s[1] << 32) >> 32);\n printf(\"\\n\");\n // if (i%5==4) printf(\"\\n\");\n }\n return 0;\n}\n*/\n","/**\n * Fast Pseudo Random Number Generators.\n *\n * Given a seed a PRNG generates a sequence of numbers that cannot be reasonably predicted.\n * Two PRNGs must generate the same random sequence of numbers if given the same seed.\n *\n * @module prng\n */\n\nimport * as binary from './binary.js'\nimport { fromCharCode, fromCodePoint } from './string.js'\nimport * as math from './math.js'\nimport { Xoroshiro128plus } from './prng/Xoroshiro128plus.js'\nimport * as buffer from './buffer.js'\n\n/**\n * Description of the function\n * @callback generatorNext\n * @return {number} A random float in the cange of [0,1)\n */\n\n/**\n * A random type generator.\n *\n * @typedef {Object} PRNG\n * @property {generatorNext} next Generate new number\n */\n\nexport const DefaultPRNG = Xoroshiro128plus\n\n/**\n * Create a Xoroshiro128plus Pseudo-Random-Number-Generator.\n * This is the fastest full-period generator passing BigCrush without systematic failures.\n * But there are more PRNGs available in ./PRNG/.\n *\n * @param {number} seed A positive 32bit integer. Do not use negative numbers.\n * @return {PRNG}\n */\nexport const create = seed => new DefaultPRNG(seed)\n\n/**\n * Generates a single random bool.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Boolean} A random boolean\n */\nexport const bool = gen => (gen.next() >= 0.5)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int53 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint53 = (gen, min, max) => math.abs(int53(gen, min, max))\n\n/**\n * Generates a random integer with 32 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int32 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint32 = (gen, min, max) => int32(gen, min, max) >>> 0\n\n/**\n * @deprecated\n * Optimized version of prng.int32. It has the same precision as prng.int32, but should be preferred when\n * openaring on smaller ranges.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive). The max inclusive number is `binary.BITS31-1`\n * @return {Number} A random integer on [min, max]\n */\nexport const int31 = (gen, min, max) => int32(gen, min, max)\n\n/**\n * Generates a random real on [0, 1) with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Number} A random real number on [0, 1).\n */\nexport const real53 = gen => gen.next() // (((gen.next() >>> 5) * binary.BIT26) + (gen.next() >>> 6)) / MAX_SAFE_INTEGER\n\n/**\n * Generates a random character from char code 32 - 126. I.e. Characters, Numbers, special characters, and Space:\n *\n * @param {PRNG} gen A random number generator.\n * @return {string}\n *\n * (Space)!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`abcdefghijklmnopqrstuvwxyz{|}~\n */\nexport const char = gen => fromCharCode(int31(gen, 32, 126))\n\n/**\n * @param {PRNG} gen\n * @return {string} A single letter (a-z)\n */\nexport const letter = gen => fromCharCode(int31(gen, 97, 122))\n\n/**\n * @param {PRNG} gen\n * @param {number} [minLen=0]\n * @param {number} [maxLen=20]\n * @return {string} A random word (0-20 characters) without spaces consisting of letters (a-z)\n */\nexport const word = (gen, minLen = 0, maxLen = 20) => {\n const len = int31(gen, minLen, maxLen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += letter(gen)\n }\n return str\n}\n\n/**\n * TODO: this function produces invalid runes. Does not cover all of utf16!!\n *\n * @param {PRNG} gen\n * @return {string}\n */\nexport const utf16Rune = gen => {\n const codepoint = int31(gen, 0, 256)\n return fromCodePoint(codepoint)\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} [maxlen = 20]\n */\nexport const utf16String = (gen, maxlen = 20) => {\n const len = int31(gen, 0, maxlen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += utf16Rune(gen)\n }\n return str\n}\n\n/**\n * Returns one element of a given array.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Array<T>} array Non empty Array of possible values.\n * @return {T} One of the values of the supplied Array.\n * @template T\n */\nexport const oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)]\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint8Array}\n */\nexport const uint8Array = (gen, len) => {\n const buf = buffer.createUint8ArrayFromLen(len)\n for (let i = 0; i < buf.length; i++) {\n buf[i] = int32(gen, 0, binary.BITS8)\n }\n return buf\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint16Array}\n */\nexport const uint16Array = (gen, len) => new Uint16Array(uint8Array(gen, len * 2).buffer)\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint32Array}\n */\nexport const uint32Array = (gen, len) => new Uint32Array(uint8Array(gen, len * 4).buffer)\n"],"names":["binary.BITS32","math.floor","math.abs","fromCharCode","fromCodePoint","buffer.createUint8ArrayFromLen","binary.BITS8"],"mappings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AC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,iBAAgB;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,EAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,EAAC;AACtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKD,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,EAAC;AACtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC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GAAG,EAAE,GAAG,KAAK,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/prng.cjs
CHANGED
|
@@ -5,12 +5,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('./binary-ac8e39e2.cjs');
|
|
6
6
|
require('./string-ad04f734.cjs');
|
|
7
7
|
require('./math-08e068f9.cjs');
|
|
8
|
-
var prng = require('./prng-
|
|
9
|
-
require('./buffer-
|
|
10
|
-
require('./environment-
|
|
8
|
+
var prng = require('./prng-c71ea8ea.cjs');
|
|
9
|
+
require('./buffer-9c449d1d.cjs');
|
|
10
|
+
require('./environment-3c81ab2f.cjs');
|
|
11
11
|
require('./map-28a001c9.cjs');
|
|
12
12
|
require('./conditions-fb475c70.cjs');
|
|
13
13
|
require('./storage.cjs');
|
|
14
|
+
require('./function-3410854f.cjs');
|
|
15
|
+
require('./array-acefe0f2.cjs');
|
|
16
|
+
require('./object-dcdd6eed.cjs');
|
|
14
17
|
require('./number-e62129bc.cjs');
|
|
15
18
|
|
|
16
19
|
|
package/dist/prng.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prng.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prng.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/testing.cjs
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var logging = require('./logging-
|
|
6
|
-
var diff = require('./diff-
|
|
5
|
+
var logging = require('./logging-a2dc7e43.cjs');
|
|
6
|
+
var diff = require('./diff-642271b1.cjs');
|
|
7
7
|
var object = require('./object-dcdd6eed.cjs');
|
|
8
8
|
var string = require('./string-ad04f734.cjs');
|
|
9
9
|
var math = require('./math-08e068f9.cjs');
|
|
10
10
|
var random = require('./random.cjs');
|
|
11
|
-
var prng = require('./prng-
|
|
11
|
+
var prng = require('./prng-c71ea8ea.cjs');
|
|
12
12
|
var statistics = require('./statistics-c2316dca.cjs');
|
|
13
13
|
var array = require('./array-acefe0f2.cjs');
|
|
14
|
-
var environment = require('./environment-
|
|
14
|
+
var environment = require('./environment-3c81ab2f.cjs');
|
|
15
15
|
var json = require('./json-092190a1.cjs');
|
|
16
16
|
var time = require('./time-e00067da.cjs');
|
|
17
17
|
var promise = require('./promise-1a9fe712.cjs');
|
|
@@ -21,9 +21,9 @@ require('./pair-ab022bc3.cjs');
|
|
|
21
21
|
require('./dom-58958c04.cjs');
|
|
22
22
|
require('./map-28a001c9.cjs');
|
|
23
23
|
require('./eventloop-c60b5658.cjs');
|
|
24
|
-
require('./function-
|
|
24
|
+
require('./function-3410854f.cjs');
|
|
25
25
|
require('./binary-ac8e39e2.cjs');
|
|
26
|
-
require('./buffer-
|
|
26
|
+
require('./buffer-9c449d1d.cjs');
|
|
27
27
|
require('./number-e62129bc.cjs');
|
|
28
28
|
require('./conditions-fb475c70.cjs');
|
|
29
29
|
require('./storage.cjs');
|
package/encoding.js
CHANGED
|
@@ -323,7 +323,7 @@ export const _writeVarStringPolyfill = (encoder, str) => {
|
|
|
323
323
|
* @param {String} str The string that is to be encoded.
|
|
324
324
|
*/
|
|
325
325
|
/* istanbul ignore next */
|
|
326
|
-
export const writeVarString = string.utf8TextEncoder ? _writeVarStringNative : _writeVarStringPolyfill
|
|
326
|
+
export const writeVarString = (string.utf8TextEncoder && string.utf8TextEncoder.encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill
|
|
327
327
|
|
|
328
328
|
/**
|
|
329
329
|
* Write the content of another Encoder.
|
package/environment.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export function getVariable(name: string): string | null;
|
|
|
7
7
|
export function getConf(name: string): string | null;
|
|
8
8
|
export function hasConf(name: string): boolean;
|
|
9
9
|
export const production: boolean;
|
|
10
|
+
export const supportsColor: boolean;
|
|
10
11
|
//# sourceMappingURL=environment.d.ts.map
|
package/environment.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["environment.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["environment.js"],"names":[],"mappings":"AAcA,6BAC0C;AAE1C,gCAAiE;AAEjE,4BAES;AAyDF,+BAJI,MAAM,GACL,OAAO,CAGwC;AAQpD,+BALI,MAAM,cACN,MAAM,GACL,MAAM,CAIuB;AAQlC,kCAJI,MAAM,GACL,MAAM,GAAC,IAAI,CAM2C;AAM3D,8BAHI,MAAM,GACL,MAAM,GAAC,IAAI,CAGgC;AAOhD,8BAJI,MAAM,GACL,OAAO,CAIkC;AAGrD,iCAA+C;AAO/C,oCAKC"}
|
package/environment.js
CHANGED
|
@@ -8,14 +8,18 @@ import * as map from './map.js'
|
|
|
8
8
|
import * as string from './string.js'
|
|
9
9
|
import * as conditions from './conditions.js'
|
|
10
10
|
import * as storage from './storage.js'
|
|
11
|
+
import * as f from './function.js'
|
|
11
12
|
|
|
12
13
|
/* istanbul ignore next */
|
|
13
14
|
// @ts-ignore
|
|
14
|
-
export const isNode = typeof process !== 'undefined' && process.release &&
|
|
15
|
+
export const isNode = typeof process !== 'undefined' && process.release &&
|
|
16
|
+
/node|io\.js/.test(process.release.name)
|
|
15
17
|
/* istanbul ignore next */
|
|
16
18
|
export const isBrowser = typeof window !== 'undefined' && !isNode
|
|
17
19
|
/* istanbul ignore next */
|
|
18
|
-
export const isMac = typeof navigator !== 'undefined'
|
|
20
|
+
export const isMac = typeof navigator !== 'undefined'
|
|
21
|
+
? /Mac/.test(navigator.platform)
|
|
22
|
+
: false
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* @type {Map<string,string>}
|
|
@@ -50,11 +54,10 @@ const computeParams = () => {
|
|
|
50
54
|
if (currParamName !== null) {
|
|
51
55
|
params.set(currParamName, '')
|
|
52
56
|
}
|
|
53
|
-
|
|
57
|
+
// in ReactNative for example this would not be true (unless connected to the Remote Debugger)
|
|
54
58
|
} else if (typeof location === 'object') {
|
|
55
|
-
params = map.create()
|
|
56
|
-
|
|
57
|
-
;(location.search || '?').slice(1).split('&').forEach(kv => {
|
|
59
|
+
params = map.create(); // eslint-disable-next-line no-undef
|
|
60
|
+
(location.search || '?').slice(1).split('&').forEach((kv) => {
|
|
58
61
|
if (kv.length !== 0) {
|
|
59
62
|
const [key, value] = kv.split('=')
|
|
60
63
|
params.set(`--${string.fromCamelCase(key, '-')}`, value)
|
|
@@ -73,7 +76,7 @@ const computeParams = () => {
|
|
|
73
76
|
* @return {boolean}
|
|
74
77
|
*/
|
|
75
78
|
/* istanbul ignore next */
|
|
76
|
-
export const hasParam = name => computeParams().has(name)
|
|
79
|
+
export const hasParam = (name) => computeParams().has(name)
|
|
77
80
|
|
|
78
81
|
/**
|
|
79
82
|
* @param {string} name
|
|
@@ -81,7 +84,8 @@ export const hasParam = name => computeParams().has(name)
|
|
|
81
84
|
* @return {string}
|
|
82
85
|
*/
|
|
83
86
|
/* istanbul ignore next */
|
|
84
|
-
export const getParam = (name, defaultVal) =>
|
|
87
|
+
export const getParam = (name, defaultVal) =>
|
|
88
|
+
computeParams().get(name) || defaultVal
|
|
85
89
|
// export const getArgs = name => computeParams() && args
|
|
86
90
|
|
|
87
91
|
/**
|
|
@@ -89,20 +93,37 @@ export const getParam = (name, defaultVal) => computeParams().get(name) || defau
|
|
|
89
93
|
* @return {string|null}
|
|
90
94
|
*/
|
|
91
95
|
/* istanbul ignore next */
|
|
92
|
-
export const getVariable =
|
|
96
|
+
export const getVariable = (name) =>
|
|
97
|
+
isNode
|
|
98
|
+
? conditions.undefinedToNull(process.env[name.toUpperCase()])
|
|
99
|
+
: conditions.undefinedToNull(storage.varStorage.getItem(name))
|
|
93
100
|
|
|
94
101
|
/**
|
|
95
102
|
* @param {string} name
|
|
96
103
|
* @return {string|null}
|
|
97
104
|
*/
|
|
98
|
-
export const getConf =
|
|
105
|
+
export const getConf = (name) =>
|
|
106
|
+
computeParams().get('--' + name) || getVariable(name)
|
|
99
107
|
|
|
100
108
|
/**
|
|
101
109
|
* @param {string} name
|
|
102
110
|
* @return {boolean}
|
|
103
111
|
*/
|
|
104
112
|
/* istanbul ignore next */
|
|
105
|
-
export const hasConf =
|
|
113
|
+
export const hasConf = (name) =>
|
|
114
|
+
hasParam('--' + name) || getVariable(name) !== null
|
|
106
115
|
|
|
107
116
|
/* istanbul ignore next */
|
|
108
117
|
export const production = hasConf('production')
|
|
118
|
+
|
|
119
|
+
/* istanbul ignore next */
|
|
120
|
+
const forceColor = isNode &&
|
|
121
|
+
f.isOneOf(process.env.FORCE_COLOR, ['true', '1', '2'])
|
|
122
|
+
|
|
123
|
+
/* istanbul ignore next */
|
|
124
|
+
export const supportsColor = !hasParam('no-colors') &&
|
|
125
|
+
(!isNode || process.stdout.isTTY || forceColor) && (
|
|
126
|
+
!isNode || hasParam('color') || forceColor ||
|
|
127
|
+
getVariable('COLORTERM') !== null ||
|
|
128
|
+
(getVariable('TERM') || '').includes('color')
|
|
129
|
+
)
|
package/function.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export function id<A>(a: A): A;
|
|
|
5
5
|
export function equalityStrict<T>(a: T, b: T): boolean;
|
|
6
6
|
export function equalityFlat<T>(a: object | T[], b: object | T[]): boolean;
|
|
7
7
|
export function equalityDeep(a: any, b: any): boolean;
|
|
8
|
+
export function isOneOf<V, OPTS extends V>(value: V, options: OPTS[]): boolean;
|
|
8
9
|
//# sourceMappingURL=function.d.ts.map
|
package/function.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["function.js"],"names":[],"mappings":"AAeO,4BAHI,eAAe,QACf,MAAM,GAAG,CAAC,oBAYpB;AAEM,4BAAoB;AAOpB,wCAAsB;AAQtB,+BAAiB;AASjB,+CAFK,OAAO,CAE4B;AASxC,mEAFK,OAAO,CAE2N;AAOvO,gCAJI,GAAG,KACH,GAAG,GACF,OAAO,CA0ElB"}
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["function.js"],"names":[],"mappings":"AAeO,4BAHI,eAAe,QACf,MAAM,GAAG,CAAC,oBAYpB;AAEM,4BAAoB;AAOpB,wCAAsB;AAQtB,+BAAiB;AASjB,+CAFK,OAAO,CAE4B;AASxC,mEAFK,OAAO,CAE2N;AAOvO,gCAJI,GAAG,KACH,GAAG,GACF,OAAO,CA0ElB;AAUM,+EAA2D"}
|
package/function.js
CHANGED
|
@@ -138,3 +138,13 @@ export const equalityDeep = (a, b) => {
|
|
|
138
138
|
}
|
|
139
139
|
return true
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @template V
|
|
144
|
+
* @template {V} OPTS
|
|
145
|
+
*
|
|
146
|
+
* @param {V} value
|
|
147
|
+
* @param {Array<OPTS>} options
|
|
148
|
+
*/
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
export const isOneOf = (value, options) => options.includes(value)
|
package/logging.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["logging.js"],"names":[],"mappings":"AAiBA,0BAAmC;AACnC,4BAAqC;AACrC,0BAAmC;AACnC,0BAAmC;AACnC,2BAAoC;AACpC,yBAAkC;AAClC,4BAAqC;AACrC,4BAAqC;AACrC,6BAAsC;
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["logging.js"],"names":[],"mappings":"AAiBA,0BAAmC;AACnC,4BAAqC;AACrC,0BAAmC;AACnC,0BAAmC;AACnC,2BAAoC;AACpC,yBAAkC;AAClC,4BAAqC;AACrC,4BAAqC;AACrC,6BAAsC;AA6K/B,+BAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAM5C;AAMM,8BAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAM5C;AAMM,gCAFI,KAAK,QAKf;AAOM,8BAHI,MAAM,UACN,MAAM,QAWhB;AAOM,uCAHI,MAAM,UACN,MAAM,QAGoC;AAK9C,+BAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAM5C;AAKM,wCAFI,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAM5C;AAEM,iCAIN;AAMM,2CAFe,IAAI,QAG4B;AAO/C,oCAHI,iBAAiB,UACjB,MAAM,QAGqB;AAEtC,iCAAkC;AAoDlC;IACE;;OAEG;IACH,iBAFW,OAAO,EAUjB;IAPC,aAAc;IACd;;OAEG;IACH,YAFU,OAAO,CAES;IAC1B,cAAc;IAIhB;;;OAGG;IACH,YAHW,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,cAClC,OAAO,QAoCjB;IAED;;OAEG;IACH,qBAFW,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAI5C;IAED,iBAQC;IAED;;OAEG;IACH,YAFW,MAAM,MAAM,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAAC,QAa5C;IAED;;OAEG;IACH,gBAFW,KAAK,QAIf;IAED;;;OAGG;IACH,cAHW,MAAM,UACN,MAAM,QAWhB;IAED;;OAEG;IACH,eAFW,IAAI,QAMd;IAED,gBAIC;CACF;AAMM,oCAFI,OAAO,YAEsC;AAUjD,+CAHI,MAAM,aACO,GAAG,OAAE,IAAI,CA4BhC"}
|
package/logging.js
CHANGED
|
@@ -57,7 +57,7 @@ const _nodeStyleMap = {
|
|
|
57
57
|
* @param {Array<string|Symbol|Object|number>} args
|
|
58
58
|
* @return {Array<string|object|number>}
|
|
59
59
|
*/
|
|
60
|
-
const computeBrowserLoggingArgs = args => {
|
|
60
|
+
const computeBrowserLoggingArgs = (args) => {
|
|
61
61
|
const strBuilder = []
|
|
62
62
|
const styles = []
|
|
63
63
|
const currentStyle = map.create()
|
|
@@ -104,11 +104,54 @@ const computeBrowserLoggingArgs = args => {
|
|
|
104
104
|
return logArgs
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/* istanbul ignore next */
|
|
108
|
+
/**
|
|
109
|
+
* @param {Array<string|Symbol|Object|number>} args
|
|
110
|
+
* @return {Array<string|object|number>}
|
|
111
|
+
*/
|
|
112
|
+
const computeNoColorLoggingArgs = args => {
|
|
113
|
+
const strBuilder = []
|
|
114
|
+
const logArgs = []
|
|
115
|
+
|
|
116
|
+
// try with formatting until we find something unsupported
|
|
117
|
+
let i = 0
|
|
118
|
+
|
|
119
|
+
for (; i < args.length; i++) {
|
|
120
|
+
const arg = args[i]
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
const style = _nodeStyleMap[arg]
|
|
123
|
+
if (style === undefined) {
|
|
124
|
+
if (arg.constructor === String || arg.constructor === Number) {
|
|
125
|
+
strBuilder.push(arg)
|
|
126
|
+
} else {
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (i > 0) {
|
|
132
|
+
logArgs.push(strBuilder.join(''))
|
|
133
|
+
}
|
|
134
|
+
// append the rest
|
|
135
|
+
for (; i < args.length; i++) {
|
|
136
|
+
const arg = args[i]
|
|
137
|
+
/* istanbul ignore else */
|
|
138
|
+
if (!(arg instanceof Symbol)) {
|
|
139
|
+
if (arg.constructor === Object) {
|
|
140
|
+
logArgs.push(JSON.stringify(arg))
|
|
141
|
+
} else {
|
|
142
|
+
logArgs.push(arg)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return logArgs
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* istanbul ignore next */
|
|
107
150
|
/**
|
|
108
151
|
* @param {Array<string|Symbol|Object|number>} args
|
|
109
152
|
* @return {Array<string|object|number>}
|
|
110
153
|
*/
|
|
111
|
-
const computeNodeLoggingArgs = args => {
|
|
154
|
+
const computeNodeLoggingArgs = (args) => {
|
|
112
155
|
const strBuilder = []
|
|
113
156
|
const logArgs = []
|
|
114
157
|
|
|
@@ -146,7 +189,9 @@ const computeNodeLoggingArgs = args => {
|
|
|
146
189
|
}
|
|
147
190
|
|
|
148
191
|
/* istanbul ignore next */
|
|
149
|
-
const computeLoggingArgs = env.
|
|
192
|
+
const computeLoggingArgs = env.supportsColor
|
|
193
|
+
? (env.isNode ? computeNodeLoggingArgs : computeBrowserLoggingArgs)
|
|
194
|
+
: computeNoColorLoggingArgs
|
|
150
195
|
|
|
151
196
|
/**
|
|
152
197
|
* @param {Array<string|Symbol|Object|number>} args
|
|
@@ -154,7 +199,7 @@ const computeLoggingArgs = env.isNode ? computeNodeLoggingArgs : computeBrowserL
|
|
|
154
199
|
export const print = (...args) => {
|
|
155
200
|
console.log(...computeLoggingArgs(args))
|
|
156
201
|
/* istanbul ignore next */
|
|
157
|
-
vconsoles.forEach(vc => vc.print(args))
|
|
202
|
+
vconsoles.forEach((vc) => vc.print(args))
|
|
158
203
|
}
|
|
159
204
|
|
|
160
205
|
/* istanbul ignore next */
|
|
@@ -164,16 +209,16 @@ export const print = (...args) => {
|
|
|
164
209
|
export const warn = (...args) => {
|
|
165
210
|
console.warn(...computeLoggingArgs(args))
|
|
166
211
|
args.unshift(ORANGE)
|
|
167
|
-
vconsoles.forEach(vc => vc.print(args))
|
|
212
|
+
vconsoles.forEach((vc) => vc.print(args))
|
|
168
213
|
}
|
|
169
214
|
|
|
170
215
|
/* istanbul ignore next */
|
|
171
216
|
/**
|
|
172
217
|
* @param {Error} err
|
|
173
218
|
*/
|
|
174
|
-
export const printError = err => {
|
|
219
|
+
export const printError = (err) => {
|
|
175
220
|
console.error(err)
|
|
176
|
-
vconsoles.forEach(vc => vc.printError(err))
|
|
221
|
+
vconsoles.forEach((vc) => vc.printError(err))
|
|
177
222
|
}
|
|
178
223
|
|
|
179
224
|
/* istanbul ignore next */
|
|
@@ -183,10 +228,13 @@ export const printError = err => {
|
|
|
183
228
|
*/
|
|
184
229
|
export const printImg = (url, height) => {
|
|
185
230
|
if (env.isBrowser) {
|
|
186
|
-
console.log(
|
|
231
|
+
console.log(
|
|
232
|
+
'%c ',
|
|
233
|
+
`font-size: ${height}px; background-size: contain; background-repeat: no-repeat; background-image: url(${url})`
|
|
234
|
+
)
|
|
187
235
|
// console.log('%c ', `font-size: ${height}x; background: url(${url}) no-repeat;`)
|
|
188
236
|
}
|
|
189
|
-
vconsoles.forEach(vc => vc.printImg(url, height))
|
|
237
|
+
vconsoles.forEach((vc) => vc.printImg(url, height))
|
|
190
238
|
}
|
|
191
239
|
|
|
192
240
|
/* istanbul ignore next */
|
|
@@ -194,7 +242,8 @@ export const printImg = (url, height) => {
|
|
|
194
242
|
* @param {string} base64
|
|
195
243
|
* @param {number} height
|
|
196
244
|
*/
|
|
197
|
-
export const printImgBase64 = (base64, height) =>
|
|
245
|
+
export const printImgBase64 = (base64, height) =>
|
|
246
|
+
printImg(`data:image/gif;base64,${base64}`, height)
|
|
198
247
|
|
|
199
248
|
/**
|
|
200
249
|
* @param {Array<string|Symbol|Object|number>} args
|
|
@@ -202,7 +251,7 @@ export const printImgBase64 = (base64, height) => printImg(`data:image/gif;base6
|
|
|
202
251
|
export const group = (...args) => {
|
|
203
252
|
console.group(...computeLoggingArgs(args))
|
|
204
253
|
/* istanbul ignore next */
|
|
205
|
-
vconsoles.forEach(vc => vc.group(args))
|
|
254
|
+
vconsoles.forEach((vc) => vc.group(args))
|
|
206
255
|
}
|
|
207
256
|
|
|
208
257
|
/**
|
|
@@ -211,28 +260,29 @@ export const group = (...args) => {
|
|
|
211
260
|
export const groupCollapsed = (...args) => {
|
|
212
261
|
console.groupCollapsed(...computeLoggingArgs(args))
|
|
213
262
|
/* istanbul ignore next */
|
|
214
|
-
vconsoles.forEach(vc => vc.groupCollapsed(args))
|
|
263
|
+
vconsoles.forEach((vc) => vc.groupCollapsed(args))
|
|
215
264
|
}
|
|
216
265
|
|
|
217
266
|
export const groupEnd = () => {
|
|
218
267
|
console.groupEnd()
|
|
219
268
|
/* istanbul ignore next */
|
|
220
|
-
vconsoles.forEach(vc => vc.groupEnd())
|
|
269
|
+
vconsoles.forEach((vc) => vc.groupEnd())
|
|
221
270
|
}
|
|
222
271
|
|
|
223
272
|
/* istanbul ignore next */
|
|
224
273
|
/**
|
|
225
274
|
* @param {function():Node} createNode
|
|
226
275
|
*/
|
|
227
|
-
export const printDom = createNode =>
|
|
228
|
-
vconsoles.forEach(vc => vc.printDom(createNode()))
|
|
276
|
+
export const printDom = (createNode) =>
|
|
277
|
+
vconsoles.forEach((vc) => vc.printDom(createNode()))
|
|
229
278
|
|
|
230
279
|
/* istanbul ignore next */
|
|
231
280
|
/**
|
|
232
281
|
* @param {HTMLCanvasElement} canvas
|
|
233
282
|
* @param {number} height
|
|
234
283
|
*/
|
|
235
|
-
export const printCanvas = (canvas, height) =>
|
|
284
|
+
export const printCanvas = (canvas, height) =>
|
|
285
|
+
printImg(canvas.toDataURL(), height)
|
|
236
286
|
|
|
237
287
|
export const vconsoles = new Set()
|
|
238
288
|
|
|
@@ -241,7 +291,7 @@ export const vconsoles = new Set()
|
|
|
241
291
|
* @param {Array<string|Symbol|Object|number>} args
|
|
242
292
|
* @return {Array<Element>}
|
|
243
293
|
*/
|
|
244
|
-
const _computeLineSpans = args => {
|
|
294
|
+
const _computeLineSpans = (args) => {
|
|
245
295
|
const spans = []
|
|
246
296
|
const currentStyle = new Map()
|
|
247
297
|
// try with formatting until we find something unsupported
|
|
@@ -255,7 +305,9 @@ const _computeLineSpans = args => {
|
|
|
255
305
|
} else {
|
|
256
306
|
if (arg.constructor === String || arg.constructor === Number) {
|
|
257
307
|
// @ts-ignore
|
|
258
|
-
const span = dom.element('span', [
|
|
308
|
+
const span = dom.element('span', [
|
|
309
|
+
pair.create('style', dom.mapToStyleString(currentStyle))
|
|
310
|
+
], [dom.text(arg.toString())])
|
|
259
311
|
if (span.innerHTML === '') {
|
|
260
312
|
span.innerHTML = ' '
|
|
261
313
|
}
|
|
@@ -272,13 +324,16 @@ const _computeLineSpans = args => {
|
|
|
272
324
|
if (content.constructor !== String && content.constructor !== Number) {
|
|
273
325
|
content = ' ' + json.stringify(content) + ' '
|
|
274
326
|
}
|
|
275
|
-
spans.push(
|
|
327
|
+
spans.push(
|
|
328
|
+
dom.element('span', [], [dom.text(/** @type {string} */ (content))])
|
|
329
|
+
)
|
|
276
330
|
}
|
|
277
331
|
}
|
|
278
332
|
return spans
|
|
279
333
|
}
|
|
280
334
|
|
|
281
|
-
const lineStyle =
|
|
335
|
+
const lineStyle =
|
|
336
|
+
'font-family:monospace;border-bottom:1px solid #e2e2e2;padding:2px;'
|
|
282
337
|
|
|
283
338
|
/* istanbul ignore next */
|
|
284
339
|
export class VConsole {
|
|
@@ -301,16 +356,33 @@ export class VConsole {
|
|
|
301
356
|
*/
|
|
302
357
|
group (args, collapsed = false) {
|
|
303
358
|
eventloop.enqueue(() => {
|
|
304
|
-
const triangleDown = dom.element('span', [
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
359
|
+
const triangleDown = dom.element('span', [
|
|
360
|
+
pair.create('hidden', collapsed),
|
|
361
|
+
pair.create('style', 'color:grey;font-size:120%;')
|
|
362
|
+
], [dom.text('▼')])
|
|
363
|
+
const triangleRight = dom.element('span', [
|
|
364
|
+
pair.create('hidden', !collapsed),
|
|
365
|
+
pair.create('style', 'color:grey;font-size:125%;')
|
|
366
|
+
], [dom.text('▶')])
|
|
367
|
+
const content = dom.element(
|
|
368
|
+
'div',
|
|
369
|
+
[pair.create(
|
|
370
|
+
'style',
|
|
371
|
+
`${lineStyle};padding-left:${this.depth * 10}px`
|
|
372
|
+
)],
|
|
373
|
+
[triangleDown, triangleRight, dom.text(' ')].concat(
|
|
374
|
+
_computeLineSpans(args)
|
|
375
|
+
)
|
|
376
|
+
)
|
|
377
|
+
const nextContainer = dom.element('div', [
|
|
378
|
+
pair.create('hidden', collapsed)
|
|
379
|
+
])
|
|
308
380
|
const nextLine = dom.element('div', [], [content, nextContainer])
|
|
309
381
|
dom.append(this.ccontainer, [nextLine])
|
|
310
382
|
this.ccontainer = nextContainer
|
|
311
383
|
this.depth++
|
|
312
384
|
// when header is clicked, collapse/uncollapse container
|
|
313
|
-
dom.addEventListener(content, 'click',
|
|
385
|
+
dom.addEventListener(content, 'click', (_event) => {
|
|
314
386
|
nextContainer.toggleAttribute('hidden')
|
|
315
387
|
triangleDown.toggleAttribute('hidden')
|
|
316
388
|
triangleRight.toggleAttribute('hidden')
|
|
@@ -340,7 +412,14 @@ export class VConsole {
|
|
|
340
412
|
*/
|
|
341
413
|
print (args) {
|
|
342
414
|
eventloop.enqueue(() => {
|
|
343
|
-
dom.append(this.ccontainer, [
|
|
415
|
+
dom.append(this.ccontainer, [
|
|
416
|
+
dom.element('div', [
|
|
417
|
+
pair.create(
|
|
418
|
+
'style',
|
|
419
|
+
`${lineStyle};padding-left:${this.depth * 10}px`
|
|
420
|
+
)
|
|
421
|
+
], _computeLineSpans(args))
|
|
422
|
+
])
|
|
344
423
|
})
|
|
345
424
|
}
|
|
346
425
|
|
|
@@ -357,7 +436,12 @@ export class VConsole {
|
|
|
357
436
|
*/
|
|
358
437
|
printImg (url, height) {
|
|
359
438
|
eventloop.enqueue(() => {
|
|
360
|
-
dom.append(this.ccontainer, [
|
|
439
|
+
dom.append(this.ccontainer, [
|
|
440
|
+
dom.element('img', [
|
|
441
|
+
pair.create('src', url),
|
|
442
|
+
pair.create('height', `${math.round(height * 1.5)}px`)
|
|
443
|
+
])
|
|
444
|
+
])
|
|
361
445
|
})
|
|
362
446
|
}
|
|
363
447
|
|
|
@@ -381,7 +465,7 @@ export class VConsole {
|
|
|
381
465
|
/**
|
|
382
466
|
* @param {Element} dom
|
|
383
467
|
*/
|
|
384
|
-
export const createVConsole = dom => new VConsole(dom)
|
|
468
|
+
export const createVConsole = (dom) => new VConsole(dom)
|
|
385
469
|
|
|
386
470
|
const loggingColors = [GREEN, PURPLE, ORANGE, BLUE]
|
|
387
471
|
let nextColor = 0
|
|
@@ -391,10 +475,12 @@ let lastLoggingTime = time.getUnixTime()
|
|
|
391
475
|
* @param {string} moduleName
|
|
392
476
|
* @return {function(...any):void}
|
|
393
477
|
*/
|
|
394
|
-
export const createModuleLogger = moduleName => {
|
|
478
|
+
export const createModuleLogger = (moduleName) => {
|
|
395
479
|
const color = loggingColors[nextColor]
|
|
396
480
|
const debugRegexVar = env.getVariable('log')
|
|
397
|
-
const doLogging = debugRegexVar !== null &&
|
|
481
|
+
const doLogging = debugRegexVar !== null &&
|
|
482
|
+
(debugRegexVar === '*' || debugRegexVar === 'true' ||
|
|
483
|
+
new RegExp(debugRegexVar, 'gi').test(moduleName))
|
|
398
484
|
nextColor = (nextColor + 1) % loggingColors.length
|
|
399
485
|
moduleName += ': '
|
|
400
486
|
|
|
@@ -402,6 +488,17 @@ export const createModuleLogger = moduleName => {
|
|
|
402
488
|
const timeNow = time.getUnixTime()
|
|
403
489
|
const timeDiff = timeNow - lastLoggingTime
|
|
404
490
|
lastLoggingTime = timeNow
|
|
405
|
-
print(
|
|
491
|
+
print(
|
|
492
|
+
color,
|
|
493
|
+
moduleName,
|
|
494
|
+
UNCOLOR,
|
|
495
|
+
...args.map((arg) =>
|
|
496
|
+
(typeof arg === 'string' || typeof arg === 'symbol')
|
|
497
|
+
? arg
|
|
498
|
+
: JSON.stringify(arg)
|
|
499
|
+
),
|
|
500
|
+
color,
|
|
501
|
+
' +' + timeDiff + 'ms'
|
|
502
|
+
)
|
|
406
503
|
}
|
|
407
504
|
}
|