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

@fluent/dedent

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluent/dedent

A template literal tag for dedenting Fluent code

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
217
decreased by-68.32%
Maintainers
4
Weekly downloads
 
Created
Source

@fluent/dedent

@fluent/dedent provides a template literal tag to dedent Fluent code. It's part of Project Fluent.

Fluent Syntax is indentation-sensitive, and @fluent/dedent offers a convenient way to include Fluent snippets in source code keeping the current level of indentation and without compromising the readability.

Installation

@fluent/dedent 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 FluentDedent global).

npm install @fluent/dedent

How to use

@fluent/dedent's default export is meant to be used as a template literal tag. By convention, the tag is often called ftl.

import ftl from "@fluent/dedent";

let messages = ftl`
    hello = Hello, world!
    welcome = Welcome, {$userName}!
    `;

The position of the closing backtick defines how much indent will be removed from each line of the content. If the indentation is not sufficient in any of the non-blank lines of the content, a RangeError is thrown.

import ftl from "@fluent/dedent";

let messages = ftl`
    hello = Hello, world!
  welcome = Welcome, {$userName}!
    `;

// → RangeError("Insufficient indentation in line 2.")

Content must start on a new line and must end on a line of its own. The closing delimiter must appear on a new line. The first and the last line of the input will be removed from the output. If any of them contains non-whitespace characters, a RangeError is thrown.

import ftl from "@fluent/dedent";

let message1 = "hello = Hello, world!";
let message2 = ftl`
    hello = Hello, world!
    `;

assert(message1 === message2);

If you wish to include the leading or trailing line breaks in the output, put extra blank lines in the input.

import ftl from "@fluent/dedent";

let message = ftl`

    hello = Hello, world!

    `;

assert(message === "\nhello = Hello, world!\n");

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