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

@types/moo

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/moo

TypeScript definitions for moo

  • 0.5.9
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
132K
decreased by-18.6%
Maintainers
1
Weekly downloads
 
Created

What is @types/moo?

@types/moo provides TypeScript type definitions for the Moo library, which is a tokenizer for JavaScript. Moo is used to create lexers that can tokenize strings based on specified rules.

What are @types/moo's main functionalities?

Basic Tokenization

This feature allows you to define a set of rules for tokenizing a string. The code sample demonstrates how to create a lexer that can tokenize whitespace, numbers, words, and newlines.

const moo = require('moo');

const lexer = moo.compile({
  WS: /[ \t]+/,
  number: /[0-9]+/,
  word: /[a-zA-Z]+/,
  NL: { match: /\n/, lineBreaks: true },
});

lexer.reset('foo 123\nbar');

let token;
while (token = lexer.next()) {
  console.log(token);
}

Custom Token Properties

This feature allows you to define custom properties for tokens. The code sample shows how to convert the value of number tokens to a JavaScript number.

const moo = require('moo');

const lexer = moo.compile({
  WS: /[ \t]+/,
  number: { match: /[0-9]+/, value: x => Number(x) },
  word: /[a-zA-Z]+/,
  NL: { match: /\n/, lineBreaks: true },
});

lexer.reset('foo 123\nbar');

let token;
while (token = lexer.next()) {
  console.log(token);
}

Error Handling

This feature allows you to handle errors during tokenization. The code sample demonstrates how to catch and handle unexpected characters in the input string.

const moo = require('moo');

const lexer = moo.compile({
  WS: /[ \t]+/,
  number: /[0-9]+/,
  word: /[a-zA-Z]+/,
  NL: { match: /\n/, lineBreaks: true },
  error: moo.error,
});

lexer.reset('foo 123\nbar$');

let token;
while (token = lexer.next()) {
  if (token.type === 'error') {
    console.error('Unexpected character:', token);
  } else {
    console.log(token);
  }
}

Other packages similar to @types/moo

FAQs

Package last updated on 07 Nov 2023

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