-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsort.js
101 lines (99 loc) · 3.5 KB
/
sort.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* arbitrary sort order for package.json largely pulled from:
* https://github.com/keithamus/sort-package-json/blob/main/defaultRules.md
*
* cross checked with:
* https://github.com/npm/types/blob/main/types/index.d.ts#L104
* https://docs.npmjs.com/cli/configuring-npm/package-json
*/
function packageSort (json) {
const {
name,
version,
private: isPrivate,
description,
keywords,
homepage,
bugs,
repository,
funding,
license,
author,
maintainers,
contributors,
type,
imports,
exports,
main,
browser,
types,
bin,
man,
directories,
files,
workspaces,
scripts,
config,
dependencies,
devDependencies,
peerDependencies,
peerDependenciesMeta,
optionalDependencies,
bundledDependencies,
bundleDependencies,
engines,
os,
cpu,
publishConfig,
devEngines,
licenses,
overrides,
...rest
} = json
return {
...(typeof name !== 'undefined' ? { name } : {}),
...(typeof version !== 'undefined' ? { version } : {}),
...(typeof isPrivate !== 'undefined' ? { private: isPrivate } : {}),
...(typeof description !== 'undefined' ? { description } : {}),
...(typeof keywords !== 'undefined' ? { keywords } : {}),
...(typeof homepage !== 'undefined' ? { homepage } : {}),
...(typeof bugs !== 'undefined' ? { bugs } : {}),
...(typeof repository !== 'undefined' ? { repository } : {}),
...(typeof funding !== 'undefined' ? { funding } : {}),
...(typeof license !== 'undefined' ? { license } : {}),
...(typeof author !== 'undefined' ? { author } : {}),
...(typeof maintainers !== 'undefined' ? { maintainers } : {}),
...(typeof contributors !== 'undefined' ? { contributors } : {}),
...(typeof type !== 'undefined' ? { type } : {}),
...(typeof imports !== 'undefined' ? { imports } : {}),
...(typeof exports !== 'undefined' ? { exports } : {}),
...(typeof main !== 'undefined' ? { main } : {}),
...(typeof browser !== 'undefined' ? { browser } : {}),
...(typeof types !== 'undefined' ? { types } : {}),
...(typeof bin !== 'undefined' ? { bin } : {}),
...(typeof man !== 'undefined' ? { man } : {}),
...(typeof directories !== 'undefined' ? { directories } : {}),
...(typeof files !== 'undefined' ? { files } : {}),
...(typeof workspaces !== 'undefined' ? { workspaces } : {}),
...(typeof scripts !== 'undefined' ? { scripts } : {}),
...(typeof config !== 'undefined' ? { config } : {}),
...(typeof dependencies !== 'undefined' ? { dependencies } : {}),
...(typeof devDependencies !== 'undefined' ? { devDependencies } : {}),
...(typeof peerDependencies !== 'undefined' ? { peerDependencies } : {}),
...(typeof peerDependenciesMeta !== 'undefined' ? { peerDependenciesMeta } : {}),
...(typeof optionalDependencies !== 'undefined' ? { optionalDependencies } : {}),
...(typeof bundledDependencies !== 'undefined' ? { bundledDependencies } : {}),
...(typeof bundleDependencies !== 'undefined' ? { bundleDependencies } : {}),
...(typeof engines !== 'undefined' ? { engines } : {}),
...(typeof os !== 'undefined' ? { os } : {}),
...(typeof cpu !== 'undefined' ? { cpu } : {}),
...(typeof publishConfig !== 'undefined' ? { publishConfig } : {}),
...(typeof devEngines !== 'undefined' ? { devEngines } : {}),
...(typeof licenses !== 'undefined' ? { licenses } : {}),
...(typeof overrides !== 'undefined' ? { overrides } : {}),
...rest,
}
}
module.exports = {
packageSort,
}