Files
securebit-chat/node_modules/qrcode/lib/core/numeric-data.js
lockbitchat 0f8399ec88 feat(security,ui): self-host React deps, Tailwind, fonts; strict CSP; local QR; better selection state
Replace CDN React/ReactDOM/Babel with local libs; remove Babel and inline scripts
Build Tailwind locally, add safelist; switch to assets/tailwind.css
Self-host Font Awesome and Inter (CSS + woff2); remove external font CDNs
Implement strict CSP (no unsafe-inline/eval; scripts/styles/fonts from self)
Extract inline handlers; move PWA scripts to external files
Add local QR code generation (qrcode lib) and remove api.qrserver.com
Improve SessionTypeSelector visual selection (highlighted background and ring)
Keep PWA working with service worker and offline assets
Refs: CSP hardening, offline-first, no external dependencies
2025-09-08 16:04:58 -04:00

44 lines
1.2 KiB
JavaScript

const Mode = require('./mode')
function NumericData (data) {
this.mode = Mode.NUMERIC
this.data = data.toString()
}
NumericData.getBitsLength = function getBitsLength (length) {
return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
}
NumericData.prototype.getLength = function getLength () {
return this.data.length
}
NumericData.prototype.getBitsLength = function getBitsLength () {
return NumericData.getBitsLength(this.data.length)
}
NumericData.prototype.write = function write (bitBuffer) {
let i, group, value
// The input data string is divided into groups of three digits,
// and each group is converted to its 10-bit binary equivalent.
for (i = 0; i + 3 <= this.data.length; i += 3) {
group = this.data.substr(i, 3)
value = parseInt(group, 10)
bitBuffer.put(value, 10)
}
// If the number of input digits is not an exact multiple of three,
// the final one or two digits are converted to 4 or 7 bits respectively.
const remainingNum = this.data.length - i
if (remainingNum > 0) {
group = this.data.substr(i)
value = parseInt(group, 10)
bitBuffer.put(value, remainingNum * 3 + 1)
}
}
module.exports = NumericData