Skip to content

Commit

Permalink
fix(dep): add stringify-package to project source, removing the depre…
Browse files Browse the repository at this point in the history
…cation warning on npm install (#65)
  • Loading branch information
TimothyJones authored Apr 5, 2023
2 parents bc6f792 + 5fddabf commit 3a959a7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 13 deletions.
36 changes: 36 additions & 0 deletions lib/stringify-package.js
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:/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
}
2 changes: 1 addition & 1 deletion lib/updaters/types/json.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stringifyPackage = require('stringify-package')
const stringifyPackage = require('../../stringify-package')
const detectIndent = require('detect-indent')
const detectNewline = require('detect-newline')

Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"find-up": "^5.0.0",
"git-semver-tags": "^4.0.0",
"semver": "^7.1.1",
"stringify-package": "^1.0.1",
"yargs": "^17.0.0"
},
"devDependencies": {
Expand Down
39 changes: 39 additions & 0 deletions test/stringify-package.spec.js
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)
})
})

0 comments on commit 3a959a7

Please sign in to comment.