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.
fix(dep): add stringify-package to project source, removing the depre…
…cation warning on npm install (#65)
- Loading branch information
Showing
5 changed files
with
76 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,36 @@ | ||
/* | ||
Copyright npm, Inc | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
https://github.com/npm/stringify-package/blob/main/LICENSE | ||
*/ | ||
|
||
'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) | ||
}) | ||
}) |