Completed
Pull Request — master (#226)
by
unknown
34s
created

src/barcodes/EAN_UPC/encoder.js   A

Complexity

Total Complexity 7
Complexity/F 1.75

Size

Lines of Code 20
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 1
dl 0
loc 20
rs 10
c 1
b 0
f 0
noi 0
wmc 7
mnd 2
bc 2
fnc 4
bpm 0.5
cpm 1.75

1 Function

Rating   Name   Duplication   Size   Complexity  
A encoder.js ➔ ??? 0 15 2
1
import { BINARIES } from './constants';
2
3
// Encode data string
4
const encode = (data, structure, separator) => {
5
	let encoded = data
6
		.split('')
7
		.map((val, idx) => BINARIES[structure[idx]])
8
		.map((val, idx) => val ? val[data[idx]] : '');
9
10
	if (separator) {
11
		const last = data.length - 1;
12
		encoded = encoded.map((val, idx) => (
13
			idx < last ? val + separator : val
14
		));
15
	}
16
17
	return encoded.join('');
18
};
19
20
export default encode;
21