New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@codemod-utils/json

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemod-utils/json - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

9

package.json
{
"name": "@codemod-utils/json",
"version": "0.1.1",
"version": "0.1.2",
"description": "Utilities for handling JSON",

@@ -25,6 +25,6 @@ "keywords": [

"@sondr3/minitest": "^0.1.1",
"eslint": "^8.40.0",
"eslint": "^8.42.0",
"prettier": "^2.8.8",
"@codemod-utils/tests": "0.1.2",
"@shared-configs/eslint-config": "0.0.0",
"@codemod-utils/tests": "0.1.0",
"@shared-configs/prettier": "0.0.0"

@@ -35,5 +35,2 @@ },

},
"publishConfig": {
"access": "public"
},
"scripts": {

@@ -40,0 +37,0 @@ "lint": "eslint . --cache",

@@ -8,2 +8,115 @@ [![This project uses GitHub Actions for continuous integration.](https://github.com/ijlee2/codemod-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/ijlee2/codemod-utils/actions/workflows/ci.yml)

## What is it?
`@codemod-utils/json` helps you update files like `package.json` and `tsconfig.json`.
## API
### convertToMap
Converts an object to a [Map](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map). The `Map` data structure helps you add, update, and remove entries.
<details>
<summary>Example</summary>
```js
import { convertToMap } from '@codemod-utils/json';
function updateDependencies(packageJson) {
const dependencies = convertToMap(packageJson['dependencies']);
const packagesToDelete = [
'@embroider/macros',
'ember-auto-import',
'ember-cli-babel',
'ember-cli-htmlbars',
];
packagesToDelete.forEach((packageName) => {
dependencies.delete(packageName);
});
}
```
</details>
### convertToObject
Converts a Map (back) to an object. `convertToObject` helps you update the JSON.
<details>
<summary>Example</summary>
```js
import { convertToMap, convertToObject } from '@codemod-utils/json';
function updateDependencies(packageJson) {
const dependencies = convertToMap(packageJson['dependencies']);
const packagesToDelete = [
'@embroider/macros',
'ember-auto-import',
'ember-cli-babel',
'ember-cli-htmlbars',
];
packagesToDelete.forEach((packageName) => {
dependencies.delete(packageName);
});
packageJson['dependencies'] = convertToObject(dependencies);
}
```
</details>
### readPackageJson
Reads `package.json` in the user's project. If the file is valid, `readPackageJson` returns the parsed JSON.
<details>
<summary>Example</summary>
```js
import { readPackageJson } from '@codemod-utils/json';
function analyzePackageJson(codemodOptions) {
const {
dependencies,
devDependencies,
'ember-addon': emberAddon,
name,
version,
} = readPackageJson(codemodOptions);
const projectDependencies = new Map([
...Object.entries(dependencies ?? {}),
...Object.entries(devDependencies ?? {}),
]);
// Return information that the codemod needs
return {
dependencies: projectDependencies,
hasGlint: projectDependencies.has('@glint/core'),
hasTypeScript: projectDependencies.has('typescript'),
isV1Addon: Boolean(emberAddon),
name,
version,
};
}
analyzePackageJson({
projectRoot: // ...
});
```
</details>
## Compatibility

@@ -10,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc