1 |
|
2 |
|
3 | module.exports = stringifyPackage
|
4 |
|
5 | const DEFAULT_INDENT = 2
|
6 | const CRLF = '\r\n'
|
7 | const LF = '\n'
|
8 |
|
9 | function stringifyPackage (data, indent, newline) {
|
10 | indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
|
11 | const json = JSON.stringify(data, null, indent)
|
12 |
|
13 | if (newline === CRLF) {
|
14 | return json.replace(/\n/g, CRLF) + CRLF
|
15 | }
|
16 |
|
17 | return json + LF
|
18 | }
|