MCPcopy Create free account
hub / github.com/breck7/scroll / encodeSegments

Method encodeSegments

external/.qrcodegen.js:13–38  ·  view source on GitHub ↗
(t, n, i = 1, a = 40, l = -1, h = !0)

Source from the content-addressed store, hash-verified

11 return e.encodeSegments([o], n)
12 }
13 static encodeSegments(t, n, i = 1, a = 40, l = -1, h = !0) {
14 if (!(e.MIN_VERSION <= i && i <= a && a <= e.MAX_VERSION) || l < -1 || l > 7) throw new RangeError("Invalid value")
15 let u, c
16 for (u = i; ; u++) {
17 const r = 8 * e.getNumDataCodewords(u, n),
18 o = s.getTotalBits(t, u)
19 if (o <= r) {
20 c = o
21 break
22 }
23 if (u >= a) throw new RangeError("Data too long")
24 }
25 for (const t of [e.Ecc.MEDIUM, e.Ecc.QUARTILE, e.Ecc.HIGH]) h && c <= 8 * e.getNumDataCodewords(u, t) && (n = t)
26 let d = []
27 for (const e of t) {
28 r(e.mode.modeBits, 4, d), r(e.numChars, e.mode.numCharCountBits(u), d)
29 for (const t of e.getData()) d.push(t)
30 }
31 o(d.length == c)
32 const f = 8 * e.getNumDataCodewords(u, n)
33 o(d.length <= f), r(0, Math.min(4, f - d.length), d), r(0, (8 - (d.length % 8)) % 8, d), o(d.length % 8 == 0)
34 for (let t = 236; d.length < f; t ^= 253) r(t, 8, d)
35 let m = []
36 for (; 8 * m.length < d.length; ) m.push(0)
37 return d.forEach((t, e) => (m[e >>> 3] |= t << (7 - (7 & e)))), new e(u, n, m, l)
38 }
39 constructor(t, r, n, s) {
40 if (((this.version = t), (this.errorCorrectionLevel = r), (this.modules = []), (this.isFunction = []), t < e.MIN_VERSION || t > e.MAX_VERSION)) throw new RangeError("Version value out of range")
41 if (s < -1 || s > 7) throw new RangeError("Mask value out of range")

Callers 2

encodeTextMethod · 0.80
encodeBinaryMethod · 0.80

Calls 8

getNumDataCodewordsMethod · 0.80
getTotalBitsMethod · 0.80
numCharCountBitsMethod · 0.80
getDataMethod · 0.80
minMethod · 0.80
forEachMethod · 0.80
rFunction · 0.70
oFunction · 0.70

Tested by

no test coverage detected