Socket
Socket
Sign inDemoInstall

organize-pkg

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

15

index.js

@@ -9,9 +9,14 @@ #!/usr/bin/env node

*/
const utils=require("./utils");const params=utils.getExtraArgs();function help(msg=""){console.log(`${msg}
command: organize-pkg -keys "main,//,defs" [-out <output json path>]
const utils=require("./utils");const params=utils.getExtraArgs();const cliName="organize-pkg";function help(msg=`${cliName} usage`){console.log(`
${msg}
${cliName} -keys "<key>,<key>,..." -out <output json path>
`);}
function isInvalidValue(value,msg){if(value===void 0||value.length===0){help(msg);return 1;}
return 0}
function organizePackageJson(){const rootPkgJsonPath="./package.json";let pkgJson;try{pkgJson=utils.readJson(rootPkgJsonPath);}catch(e){console.error(e);return;}
if(pkgJson){const keys=params.keys;if(keys===void 0||keys.length===0){help(`"-keys" parameter must be required!!`);return;}
keys.forEach(key=>{delete pkgJson[key];});let dest=params.out||rootPkgJsonPath;if(!/\.json$/.test(dest)){const last=[...dest].pop();dest=(last==="/"||last==="\\")?dest+"package.json":`${dest}/package.json`}
utils.writeTextUTF8(JSON.stringify(pkgJson,null,2),dest);}else{help("organize-pkg usage");}}
if(pkgJson){const keys=params.keys;if(isInvalidValue(keys,`ERROR: "-keys" parameter must be required`)){return;}
let dest=params.out;if(isInvalidValue(dest,`ERROR: "-out" parameter must be required`)){return;}
keys.forEach(key=>delete pkgJson[key]);if(!/\.json$/.test(dest)){const last=[...dest].pop();dest=(last==="/"||last==="\\")?dest+"package.json":`${dest}/package.json`}
utils.writeTextUTF8(JSON.stringify(pkgJson,null,2),dest);}else{help();}}
organizePackageJson();
{
"name": "organize-pkg",
"description": "very simple package.json organizer",
"version": "1.0.0",
"version": "1.1.0",
"bin": "index.js",

@@ -6,0 +6,0 @@ "files": [

@@ -14,7 +14,5 @@ # organize package json (organize-pkg) ![MIT](https://img.shields.io/badge/license-MIT-brightgreen)

```
organize-pkg -keys "<key>,<key>,..." [-out ./output.json]
organize-pkg -keys "<key>,<key>,..." -out ./output.json
```
* `out` option is optional (**default behavior is overwrite package.json**)
```shell

@@ -21,0 +19,0 @@ # file name is output as "./dist/package.json"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc