Skip to content

Commit 5b44502

Browse files
committed
chore(dep): add stringify-package to project source
1 parent bc6f792 commit 5b44502

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

lib/stringify-package.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict'
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+
}

lib/updaters/types/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const stringifyPackage = require('stringify-package')
1+
const stringifyPackage = require('../../stringify-package')
22
const detectIndent = require('detect-indent')
33
const detectNewline = require('detect-newline')
44

package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"find-up": "^5.0.0",
5353
"git-semver-tags": "^4.0.0",
5454
"semver": "^7.1.1",
55-
"stringify-package": "^1.0.1",
5655
"yargs": "^17.0.0"
5756
},
5857
"devDependencies": {

test/stringify-package.spec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* global describe it */
2+
3+
'use strict'
4+
5+
const stringifyPackage = require('../lib/stringify-package')
6+
7+
require('chai').should()
8+
9+
describe('stringifyPackage()', function () {
10+
const dummy = { name: 'dummy' }
11+
12+
it('with no params uses \\n', function () {
13+
stringifyPackage(dummy).should.match(/\n$/m)
14+
})
15+
16+
it('uses \\n', function () {
17+
stringifyPackage(dummy, 2, '\n').should.match(/\n$/m)
18+
})
19+
20+
it('uses \\r\\n', function () {
21+
stringifyPackage(dummy, 2, '\r\n').should.match(/\r\n$/m)
22+
})
23+
24+
it('with no params uses 2-space indent', function () {
25+
stringifyPackage(dummy).should.match(/^ {2}"name": "dummy"/m)
26+
})
27+
28+
it('uses 2-space indent', function () {
29+
stringifyPackage(dummy, 2, '\n').should.match(/^ {2}"name": "dummy"/m)
30+
})
31+
32+
it('uses 4-space indent', function () {
33+
stringifyPackage(dummy, 4, '\n').should.match(/^ {4}"name": "dummy"/m)
34+
})
35+
36+
it('0 works', function () {
37+
stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length.should.equal(2)
38+
})
39+
})

0 commit comments

Comments
 (0)