Socket
Book a DemoInstallSign in
Socket

@humanwhocodes/momoa

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@humanwhocodes/momoa

JSON AST parser, tokenizer, printer, traverser.

2.0.3
Source
npmnpm
Version published
Weekly downloads
1.3M
2.43%
Maintainers
1
Weekly downloads
 
Created

What is @humanwhocodes/momoa?

@humanwhocodes/momoa is a JavaScript library for parsing and manipulating JSON Abstract Syntax Trees (ASTs). It provides a way to work with JSON data structures at a lower level, allowing for more advanced operations such as transformations, validations, and custom traversals.

What are @humanwhocodes/momoa's main functionalities?

Parsing JSON into AST

This feature allows you to parse a JSON string into an Abstract Syntax Tree (AST). The AST can then be used for further analysis or transformation.

const { parse } = require('@humanwhocodes/momoa');
const json = '{"key": "value"}';
const ast = parse(json);
console.log(ast);

Traversing the AST

This feature allows you to traverse the AST. You can define enter and leave methods to perform actions when entering or leaving nodes in the AST.

const { traverse } = require('@humanwhocodes/momoa');
const ast = parse('{"key": "value"}');
traverse(ast, {
  enter(node) {
    console.log(node.type);
  }
});

Transforming the AST

This feature allows you to transform the AST. In this example, the value of a string node is changed, and the modified AST is then converted back into a JSON string.

const { parse, generate, traverse } = require('@humanwhocodes/momoa');
let ast = parse('{"key": "value"}');
traverse(ast, {
  enter(node) {
    if (node.type === 'String') {
      node.value = 'newValue';
    }
  }
});
const newJson = generate(ast);
console.log(newJson);

Other packages similar to @humanwhocodes/momoa

Keywords

json

FAQs

Package last updated on 18 Feb 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.