Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@humanwhocodes/momoa

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

@humanwhocodes/momoa

JSON AST parser, tokenizer, printer, traverser.

  • 3.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
550K
increased by10.23%
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

FAQs

Package last updated on 05 Dec 2024

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

  • 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