source: trip-planner-front/node_modules/read-package-json-fast/README.md@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1# read-package-json-fast
2
3Like [`read-package-json`](http://npm.im/read-package-json), but faster and
4more accepting of "missing" data.
5
6This is only suitable for reading package.json files in a node_modules
7tree, since it doesn't do the various cleanups, normalization, and warnings
8that are beneficial at the root level in a package being published.
9
10## USAGE
11
12```js
13const rpj = require('read-package-json-fast')
14
15// typical promisey type API
16rpj('/path/to/package.json')
17 .then(data => ...)
18 .catch(er => ...)
19
20// or just normalize a package manifest
21const normalized = rpj.normalize(packageJsonObject)
22```
23
24Errors raised from parsing will use
25[`json-parse-even-better-errors`](http://npm.im/json-parse-even-better-errors),
26so they'll be of type `JSONParseError` and have a `code: 'EJSONPARSE'`
27property. Errors will also always have a `path` member referring to the
28path originally passed into the function.
29
30## Indentation
31
32To preserve indentation when the file is saved back to disk, use
33`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and
34if you want to preserve windows `\r\n` newlines, replace the `\n` chars in
35the string with `data[Symbol.for('newline')]`.
36
37For example:
38
39```js
40const data = await readPackageJsonFast('./package.json')
41const indent = Symbol.for('indent')
42const newline = Symbol.for('newline')
43// .. do some stuff to the data ..
44const string = JSON.stringify(data, null, data[indent]) + '\n'
45const eolFixed = data[newline] === '\n' ? string
46 : string.replace(/\n/g, data[newline])
47await writeFile('./package.json', eolFixed)
48```
49
50Indentation is determined by looking at the whitespace between the initial
51`{` and the first `"` that follows it. If you have lots of weird
52inconsistent indentation, then it won't track that or give you any way to
53preserve it. Whether this is a bug or a feature is debatable ;)
54
55## WHAT THIS MODULE DOES
56
57- Parse JSON
58- Normalize `bundledDependencies`/`bundleDependencies` naming to just
59 `bundleDependencies` (without the extra `d`)
60- Handle `true`, `false`, or object values passed to `bundleDependencies`
61- Normalize `funding: <string>` to `funding: { url: <string> }`
62- Remove any `scripts` members that are not a string value.
63- Normalize a string `bin` member to `{ [name]: bin }`.
64- Fold `optionalDependencies` into `dependencies`.
65- Set the `_id` property if name and version are set. (This is
66 load-bearing in a few places within the npm CLI.)
67
68## WHAT THIS MODULE DOES NOT DO
69
70- Warn about invalid/missing name, version, repository, etc.
71- Extract a description from the `README.md` file, or attach the readme to
72 the parsed data object.
73- Read the `HEAD` value out of the `.git` folder.
74- Warn about potentially typo'ed scripts (eg, `tset` instead of `test`)
75- Check to make sure that all the files in the `files` field exist and are
76 valid files.
77- Fix bundleDependencies that are not listed in `dependencies`.
78- Fix `dependencies` fields that are not strictly objects of string values.
79- Anything involving the `directories` field (ie, bins, mans, and so on).
Note: See TracBrowser for help on using the repository browser.