summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/stringify-package/index.js
blob: cd291f295a59ca7acfa3cdc6ba54898f38e3de2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'use strict'

module.exports = stringifyPackage

const DEFAULT_INDENT = 2
const CRLF = '\r\n'
const LF = '\n'

function stringifyPackage (data, indent, newline) {
  indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT)
  const json = JSON.stringify(data, null, indent)

  if (newline === CRLF) {
    return json.replace(/\n/g, CRLF) + CRLF
  }

  return json + LF
}