Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@fluent/syntax
Advanced tools
@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.
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);
MessageFormat is a library for handling both pluralization and gender in messages. It is more focused on ICU MessageFormat syntax, which is different from Fluent syntax. While @fluent/syntax is designed for the Fluent localization system, messageformat is more general-purpose and can be used for various localization needs.
i18next is a widely-used internationalization framework for JavaScript. It provides a comprehensive solution for managing translations, including interpolation, pluralization, and context. Unlike @fluent/syntax, which is specific to Fluent syntax, i18next supports multiple formats and is highly extensible.
format-message is a library for formatting messages with ICU MessageFormat syntax. It provides similar functionality to @fluent/syntax but uses a different syntax standard. It is useful for applications that need to support complex message formatting and localization.
@fluent/syntax
is a tooling library for parsing, serializing, and working
with the Fluent syntax. It's part of Project Fluent.
@fluent/syntax
can be used both on the client-side and the server-side. You
can install it from the npm registry or use it as a standalone script (as the
FluentSyntax
global).
npm install @fluent/syntax
import { parse, Resource } from "@fluent/syntax";
const res = parse(`
-brand-name = Foo 3000
welcome = Welcome, {$name}, to {-brand-name}!
`);
assert(res instanceof Resource);
The API reference is available at https://projectfluent.org/fluent.js/syntax.
FAQs
AST and parser for Fluent
The npm package @fluent/syntax receives a total of 103,771 weekly downloads. As such, @fluent/syntax popularity was classified as popular.
We found that @fluent/syntax demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.