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

module.exports = stringifyPackage

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

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

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

  return json + LF
}