Passed
Branch v15.x (8faa65)
by Rafael S.
02:24
created

shims.js ➔ packString   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
/**
2
 * Write a string of UTF-8 characters as a byte buffer.
3
 * @param {string} str The string to pack.
4
 * @return {!Uint8Array|Array<number>} The buffer with the packed string written.
5
 */
6
function packString (str) {
7
  var buffer;
8
  if (typeof Uint8Array === 'function') {
9
    buffer =  new Uint8Array(utf8BufferSize(str));
10
  } else {
11
    buffer = [];
12
  }
13
  pack(str, buffer, 0);
14
  return buffer;
15
}
16