Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@codemod-utils/json
Advanced tools
Utilities for handling JSON
@codemod-utils/json
helps you update files like package.json
and tsconfig.json
.
convertToMap()
converts an object to a Map, while convertToObject()
converts the Map back to an object. Use these two utilities to update JSONs.
[!NOTE]
convertToObject()
creates an object with keys in alphabetical order.
Remove dependencies (if they exist) from package.json
.
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);
Configure tsconfig.json
in an Ember app.
const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
compilerOptions.set('paths', {
[`${appName}/tests/*`]: ['tests/*'],
[`${appName}/*`]: ['app/*'],
'*': ['types/*'],
});
tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
Reads package.json
and returns the parsed JSON.
[!NOTE]
readPackageJson()
checks thatpackage.json
exists and is a valid JSON.
Check if the project, against which the codemod is run, has typescript
as a dependency.
import { readPackageJson } from '@codemod-utils/json';
const { dependencies, devDependencies } = readPackageJson({
projectRoot,
});
const projectDependencies = new Map([
...Object.entries(dependencies ?? {}),
...Object.entries(devDependencies ?? {}),
]);
const hasTypeScript = projectDependencies.has('typescript');
Check if the fields name
and version
exist, in the sense that their values are a non-empty string.
[!NOTE] You may still need the non-null assertion operator
!
, to tell TypeScript thatname
andversion
are notundefined
.
import { readPackageJson, validatePackageJson } from '@codemod-utils/json';
const packageJson = readPackageJson({
projectRoot,
});
validatePackageJson(packageJson);
const { name, version } = packageJson;
See the Contributing guide for details.
This project is licensed under the MIT License.
FAQs
Utilities for handling JSON
The npm package @codemod-utils/json receives a total of 25 weekly downloads. As such, @codemod-utils/json popularity was classified as not popular.
We found that @codemod-utils/json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.