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

@fluent/syntax

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluent/syntax

AST and parser for Fluent

  • 0.19.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
decreased by-3.46%
Maintainers
4
Weekly downloads
 
Created

What is @fluent/syntax?

@fluent/syntax is a JavaScript library for working with Fluent syntax, which is a localization system designed by Mozilla. It allows developers to parse, serialize, and manipulate Fluent translation files, making it easier to manage and work with localized content.

What are @fluent/syntax's main functionalities?

Parsing Fluent Syntax

This feature allows you to parse Fluent syntax strings into an abstract syntax tree (AST). The code sample demonstrates how to parse a simple Fluent message.

const { parse } = require('@fluent/syntax');
const source = `
hello = Hello, world!
`; 
const resource = parse(source);
console.log(resource);

Serializing Fluent Syntax

This feature allows you to serialize an AST back into Fluent syntax. The code sample demonstrates how to serialize a simple Fluent message.

const { serialize } = require('@fluent/syntax');
const resource = {
  type: 'Resource',
  body: [
    {
      type: 'Message',
      id: { type: 'Identifier', name: 'hello' },
      value: { type: 'Pattern', elements: [{ type: 'TextElement', value: 'Hello, world!' }] }
    }
  ]
};
const source = serialize(resource);
console.log(source);

Manipulating Fluent AST

This feature allows you to manipulate the AST of a Fluent message. The code sample demonstrates how to change the value of a message and serialize it back to Fluent syntax.

const { parse, serialize } = require('@fluent/syntax');
const source = `
hello = Hello, world!
`;
let resource = parse(source);
resource.body[0].value.elements[0].value = 'Hello, universe!';
const updatedSource = serialize(resource);
console.log(updatedSource);

Other packages similar to @fluent/syntax

Keywords

FAQs

Package last updated on 13 Mar 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