[SignalingServer] Optimize dependent modules
[platform/framework/web/wrtjs.git] / signaling_server / service / node_modules / qrcode / lib / core / numeric-data.js
1 var Mode = require('./mode')
2
3 function NumericData (data) {
4   this.mode = Mode.NUMERIC
5   this.data = data.toString()
6 }
7
8 NumericData.getBitsLength = function getBitsLength (length) {
9   return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
10 }
11
12 NumericData.prototype.getLength = function getLength () {
13   return this.data.length
14 }
15
16 NumericData.prototype.getBitsLength = function getBitsLength () {
17   return NumericData.getBitsLength(this.data.length)
18 }
19
20 NumericData.prototype.write = function write (bitBuffer) {
21   var i, group, value
22
23   // The input data string is divided into groups of three digits,
24   // and each group is converted to its 10-bit binary equivalent.
25   for (i = 0; i + 3 <= this.data.length; i += 3) {
26     group = this.data.substr(i, 3)
27     value = parseInt(group, 10)
28
29     bitBuffer.put(value, 10)
30   }
31
32   // If the number of input digits is not an exact multiple of three,
33   // the final one or two digits are converted to 4 or 7 bits respectively.
34   var remainingNum = this.data.length - i
35   if (remainingNum > 0) {
36     group = this.data.substr(i)
37     value = parseInt(group, 10)
38
39     bitBuffer.put(value, remainingNum * 3 + 1)
40   }
41 }
42
43 module.exports = NumericData