From a9ac8712dfafcb31a4e3deca24ddb92ff75e942d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Wed, 18 Jul 2018 17:55:52 -0700 Subject: utils: use the extracted stringify-package module (#21) PR-URL: https://github.com/npm/cli/pull/21 Credit: @dpogue Reviewed-By: @zkat --- node_modules/stringify-package/CHANGELOG.md | 6 +++ node_modules/stringify-package/LICENSE | 13 ++++++ node_modules/stringify-package/README.md | 55 +++++++++++++++++++++++ node_modules/stringify-package/index.js | 17 +++++++ node_modules/stringify-package/package.json | 70 +++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 node_modules/stringify-package/CHANGELOG.md create mode 100644 node_modules/stringify-package/LICENSE create mode 100644 node_modules/stringify-package/README.md create mode 100644 node_modules/stringify-package/index.js create mode 100644 node_modules/stringify-package/package.json (limited to 'node_modules/stringify-package') diff --git a/node_modules/stringify-package/CHANGELOG.md b/node_modules/stringify-package/CHANGELOG.md new file mode 100644 index 000000000..974d393ac --- /dev/null +++ b/node_modules/stringify-package/CHANGELOG.md @@ -0,0 +1,6 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + + +# 1.0.0 (2018-07-18) diff --git a/node_modules/stringify-package/LICENSE b/node_modules/stringify-package/LICENSE new file mode 100644 index 000000000..209e4477f --- /dev/null +++ b/node_modules/stringify-package/LICENSE @@ -0,0 +1,13 @@ +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. diff --git a/node_modules/stringify-package/README.md b/node_modules/stringify-package/README.md new file mode 100644 index 000000000..1ba4f5a33 --- /dev/null +++ b/node_modules/stringify-package/README.md @@ -0,0 +1,55 @@ +# stringify-package [![npm version](https://img.shields.io/npm/v/stringify-package.svg)](https://npm.im/stringify-package) [![license](https://img.shields.io/npm/l/stringify-package.svg)](https://npm.im/stringify-package) [![Travis](https://img.shields.io/travis/npm/stringify-package/latest.svg)](https://travis-ci.org/npm/stringify-package) [![AppVeyor](https://img.shields.io/appveyor/ci/npm/stringify-package/latest.svg)](https://ci.appveyor.com/project/npm/stringify-package) [![Coverage Status](https://coveralls.io/repos/github/npm/stringify-package/badge.svg?branch=latest)](https://coveralls.io/github/npm/stringify-package?branch=latest) + +[`stringify-package`](https://github.com/npm/stringify-package) is a standalone +library for writing out package data as a JSON file. It is extracted from npm. + +## Install + +`$ npm install stringify-package` + +## Table of Contents + +* [Example](#example) +* [Features](#features) +* [Contributing](#contributing) +* [API](#api) + * [`stringifyPackage`](#stringifypackage) + +### Example + +```javascript +const fs = require('fs') +const pkg = { /* ... */ } + +fs.writeFile('package.json', stringifyPackage(pkg), 'utf8', cb(err) => { + // ... +}) +``` + +### Features + +* Ensures consistent file indentation + To match existing file indentation, + [`detect-indent`](https://npm.im/detect-indent) is recommended. + +* Ensures consistent newlines + To match existing newline characters, + [`detect-newline`](https://npm.im/detect-newline) is recommended. + +### Contributing + +The npm team enthusiastically welcomes contributions and project participation! +There's a bunch of things you can do if you want to contribute! The [Contributor +Guide](CONTRIBUTING.md) has all the information you need for everything from +reporting bugs to contributing entire new features. Please don't hesitate to +jump in if you'd like to, or even ask us questions if something isn't clear. + +### API + +### `> stringifyPackage(data, indent, newline) -> String` + +#### Arguments + +* `data` - the package data as an object to be stringified +* `indent` - the number of spaces to use for each level of indentation (defaults to 2) +* `newline` - the character(s) to be used as a line terminator diff --git a/node_modules/stringify-package/index.js b/node_modules/stringify-package/index.js new file mode 100644 index 000000000..0cc9de0a3 --- /dev/null +++ b/node_modules/stringify-package/index.js @@ -0,0 +1,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 +} diff --git a/node_modules/stringify-package/package.json b/node_modules/stringify-package/package.json new file mode 100644 index 000000000..9d2a9d5f1 --- /dev/null +++ b/node_modules/stringify-package/package.json @@ -0,0 +1,70 @@ +{ + "_from": "stringify-package@^1.0.0", + "_id": "stringify-package@1.0.0", + "_inBundle": false, + "_integrity": "sha512-JIQqiWmLiEozOC0b0BtxZ/AOUtdUZHCBPgqIZ2kSJJqGwgb9neo44XdTHUC4HZSGqi03hOeB7W/E8rAlKnGe9g==", + "_location": "/stringify-package", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "stringify-package@^1.0.0", + "name": "stringify-package", + "escapedName": "stringify-package", + "rawSpec": "^1.0.0", + "saveSpec": null, + "fetchSpec": "^1.0.0" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/stringify-package/-/stringify-package-1.0.0.tgz", + "_shasum": "e02828089333d7d45cd8c287c30aa9a13375081b", + "_spec": "stringify-package@^1.0.0", + "_where": "/Users/dpogue/Coding/npm_cli", + "author": { + "name": "Kat Marchán", + "email": "kzm@zkat.tech" + }, + "bugs": { + "url": "https://github.com/npm/stringify-package/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "stringifies npm-written json files", + "devDependencies": { + "standard": "*", + "standard-version": "*", + "tap": "*", + "weallbehave": "*", + "weallcontribute": "*" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/npm/stringify-package", + "keywords": [ + "npm", + "json", + "stringify", + "package.json" + ], + "license": "ISC", + "main": "index.js", + "name": "stringify-package", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/stringify-package.git" + }, + "scripts": { + "postrelease": "npm publish && git push --follow-tags", + "prerelease": "npm t", + "pretest": "standard", + "release": "standard-version -s", + "test": "tap -J --coverage --100 test/*.js", + "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'", + "update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'" + }, + "version": "1.0.0" +} -- cgit v1.2.3