MCPcopy
hub / github.com/webpack/webpack / randStr

Function randStr

test/cssIdentifier.unittest.js:139–153  ·  view source on GitHub ↗
(/** @type {() => number} */ rng)

Source from the content-addressed store, hash-verified

137 "-_0123456789"
138 ];
139 const randStr = (/** @type {() => number} */ rng) => {
140 const len = (rng() * 40) | 0;
141 const surrogateMode = rng() < 0.2;
142 let out = "";
143 for (let i = 0; i < len; i++) {
144 if (surrogateMode) {
145 // any BMP code unit, including lone surrogates 0xD800-0xDFFF
146 out += String.fromCharCode((rng() * 0x10000) | 0);
147 } else {
148 const pool = POOLS[(rng() * POOLS.length) | 0];
149 out += pool[(rng() * pool.length) | 0];
150 }
151 }
152 return out;
153 };
154
155 it("escape/unescape never throw and round-trip on random input", () => {
156 const rng = makeRng(0x12345678);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected