Code Duplication    Length = 41-53 lines in 3 locations

src/barcodes/CODE128/CODE128.js 3 locations

@@ 73-125 (lines=53) @@
70
		return this.string.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1;
71
	}
72
73
	nextA(bytes, depth){
74
		if(bytes.length <= 0){
75
			return {"result": "", "checksum": 0};
76
		}
77
78
		var next, index;
79
80
		// Special characters
81
		if(bytes[0] >= 200){
82
			index = bytes[0] - 105;
83
84
			// Remove first element
85
			bytes.shift();
86
87
			// Swap to CODE128C
88
			if(index === 99){
89
				next = this.nextC(bytes, depth + 1);
90
			}
91
			// Swap to CODE128B
92
			else if(index === 100){
93
				next = this.nextB(bytes, depth + 1);
94
			}
95
			// Shift
96
			else if(index === 98){
97
				// Convert the next character so that is encoded correctly
98
				bytes[0] = bytes[0] > 95 ? bytes[0] - 96 : bytes[0];
99
				next = this.nextA(bytes, depth + 1);
100
			}
101
			// Continue on CODE128A but encode a special character
102
			else{
103
				next = this.nextA(bytes, depth + 1);
104
			}
105
		}
106
		// Continue encoding of CODE128A
107
		else{
108
			var charCode = bytes[0];
109
			index = charCode < 32 ? charCode + 64 : charCode - 32;
110
111
			// Remove first element
112
			bytes.shift();
113
114
			next = this.nextA(bytes, depth + 1);
115
		}
116
117
		// Get the correct binary encoding and calculate the weight
118
		var enc = this.getEncoding(index);
119
		var weight = index * depth;
120
121
		return {
122
			"result": enc + next.result,
123
			"checksum": weight + next.checksum
124
		};
125
	}
126
127
	nextB(bytes, depth){
128
		if(bytes.length <= 0){
@@ 127-172 (lines=46) @@
124
		};
125
	}
126
127
	nextB(bytes, depth){
128
		if(bytes.length <= 0){
129
			return {"result": "", "checksum": 0};
130
		}
131
132
		var next, index;
133
134
		// Special characters
135
		if(bytes[0] >= 200){
136
			index = bytes[0] - 105;
137
138
			// Remove first element
139
			bytes.shift();
140
141
			// Swap to CODE128C
142
			if(index === 99){
143
				next = this.nextC(bytes, depth + 1);
144
			}
145
			// Swap to CODE128A
146
			else if(index === 101){
147
				next = this.nextA(bytes, depth + 1);
148
			}
149
			// Shift
150
			else if(index === 98){
151
				// Convert the next character so that is encoded correctly
152
				bytes[0] = bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
153
				next = this.nextB(bytes, depth + 1);
154
			}
155
			// Continue on CODE128B but encode a special character
156
			else{
157
				next = this.nextB(bytes, depth + 1);
158
			}
159
		}
160
		// Continue encoding of CODE128B
161
		else {
162
			index = bytes[0] - 32;
163
			bytes.shift();
164
			next = this.nextB(bytes, depth + 1);
165
		}
166
167
		// Get the correct binary encoding and calculate the weight
168
		var enc = this.getEncoding(index);
169
		var weight = index * depth;
170
171
		return {"result": enc + next.result, "checksum": weight + next.checksum};
172
	}
173
174
	nextC(bytes, depth){
175
		if(bytes.length <= 0){
@@ 174-214 (lines=41) @@
171
		return {"result": enc + next.result, "checksum": weight + next.checksum};
172
	}
173
174
	nextC(bytes, depth){
175
		if(bytes.length <= 0){
176
			return {"result": "", "checksum": 0};
177
		}
178
179
		var next, index;
180
181
		// Special characters
182
		if(bytes[0] >= 200){
183
			index = bytes[0] - 105;
184
185
			// Remove first element
186
			bytes.shift();
187
188
			// Swap to CODE128B
189
			if(index === 100){
190
				next = this.nextB(bytes, depth + 1);
191
			}
192
			// Swap to CODE128A
193
			else if(index === 101){
194
				next = this.nextA(bytes, depth + 1);
195
			}
196
			// Continue on CODE128C but encode a special character
197
			else{
198
				next = this.nextC(bytes, depth + 1);
199
			}
200
		}
201
		// Continue encoding of CODE128C
202
		else{
203
			index = (bytes[0] - 48) * 10 + bytes[1] - 48;
204
			bytes.shift();
205
			bytes.shift();
206
			next = this.nextC(bytes, depth + 1);
207
		}
208
209
		// Get the correct binary encoding and calculate the weight
210
		var enc = this.getEncoding(index);
211
		var weight = index * depth;
212
213
		return {"result": enc + next.result, "checksum": weight + next.checksum};
214
	}
215
}
216
217
export default CODE128;