forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dep): add stringify-package to project source
- Loading branch information
Showing
5 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* global describe it */ | ||
|
||
'use strict' | ||
|
||
const stringifyPackage = require('../lib/stringify-package') | ||
|
||
require('chai').should() | ||
|
||
describe('stringifyPackage()', function () { | ||
const dummy = { name: 'dummy' } | ||
|
||
it('with no params uses \\n', function () { | ||
stringifyPackage(dummy).should.match(/\n$/m) | ||
}) | ||
|
||
it('uses \\n', function () { | ||
stringifyPackage(dummy, 2, '\n').should.match(/\n$/m) | ||
}) | ||
|
||
it('uses \\r\\n', function () { | ||
stringifyPackage(dummy, 2, '\r\n').should.match(/\r\n$/m) | ||
}) | ||
|
||
it('with no params uses 2-space indent', function () { | ||
stringifyPackage(dummy).should.match(/^ {2}"name": "dummy"/m) | ||
}) | ||
|
||
it('uses 2-space indent', function () { | ||
stringifyPackage(dummy, 2, '\n').should.match(/^ {2}"name": "dummy"/m) | ||
}) | ||
|
||
it('uses 4-space indent', function () { | ||
stringifyPackage(dummy, 4, '\n').should.match(/^ {4}"name": "dummy"/m) | ||
}) | ||
|
||
it('0 works', function () { | ||
stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length.should.equal(2) | ||
}) | ||
}) |