-
Notifications
You must be signed in to change notification settings - Fork 21
/
spreadsheet.js
42 lines (36 loc) · 1.17 KB
/
spreadsheet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
--------------------------------------------------------------------------------
- lib/spreadsheet.js
--------------------------------------------------------------------------------
*/
/* eslint camelcase: 0 */
// cleanString() trims leading and trailing spaces.
// - If the entire string is enclosed in double quotes, removes them (does
// not remove a trailing or leading double quote without a corresponding
// one at the other end).
// - Converts double spaces to single spaces.
function cleanString(val) {
if (!val && val !== 0) {
return null;
}
val = String(val).trim();
if (val) {
val = val.replace(/^"(.+)"$/, '$1')
.replace(/ {2}/g, ' ')
.trim();
}
return val;
}
function zeroPad(code) {
code = String(code);
if (code.length < 3) {
code = (`000${code}`).substr(-3);
}
return code;
}
module.exports = {
cleanString,
zeroPad,
};
/* * * * */
// NOTE: This file was copied from src/server/lib/spreadsheet.js (git @ ada8bfdc98) in the arpa-reporter repo on 2022-09-23T20:05:47.735Z