# @fluent/sequence

> Manage ordered sequences of FluentBundles

Latest version **0.8.0** (published 2023-03-13) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @fluent/sequence
pnpm add @fluent/sequence
yarn add @fluent/sequence
bun add @fluent/sequence
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2023-03-13 |
| First published | 2019-07-25 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 0 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1010 |
| Author | Mozilla |
| Maintainers | eemeli, zbraniecki, tatumcreative, flod |
| Keywords | fluent, ftl |

## Links

- npm: https://www.npmjs.com/package/@fluent/sequence
- Repository: https://github.com/projectfluent/fluent.js
- Homepage: https://projectfluent.org
- Issues: https://github.com/projectfluent/fluent.js/issues
- npm.io page: https://npm.io/package/@fluent/sequence

## Recent versions

- 0.8.0 (latest) — 2023-03-13
- 0.7.0 — 2021-09-13
- 0.6.0 — 2020-07-02
- 0.5.0 — 2020-03-02
- 0.4.0 — 2019-07-25
- 0.3.0 — 2019-07-25

## README

# @fluent/sequence ![](https://github.com/projectfluent/fluent.js/workflows/test/badge.svg)

`@fluent/sequence` provides mapping functions from string identifiers to
`FluentBundle` instances taken from synchronous or asynchronous sequences.
It's part of [Project Fluent][].

[project fluent]: https://projectfluent.org

## Installation

`@fluent/sequence` 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 `FluentSequence` global).

    npm install @fluent/sequence

## How to use

An ordered iterable of `FluentBundle` instances can represent the current
negotiated fallback chain of languages. This iterable can be used to find the
best existing translation for a given identifier.

`@fluent/sequence` provides two mapping functions: `mapBundleSync`, and
`mapBundleAsync`. They can be used to find the first `FluentBundle` in the
given iterable which contains the translation with the given identifier. If
the iterable is ordered according to the result of a language negotiation the
returned `FluentBundle` contains the best available translation.

A simple function which formats translations based on the identifier might
be implemented as follows:

```js
import { mapBundleSync } from "@fluent/sequence";

function formatString(id, args) {
  // contexts is a negotiated iterable of FluentBundle instances.
  let ctx = mapBundleSync(contexts, id);

  if (ctx === null) {
    return id;
  }

  let msg = ctx.getMessage(id);
  return ctx.format(msg, args);
}
```

When passing a synchronous iterator to `mapBundleSync`, wrap it in
`CachedSyncIterable` from the [`cached-iterable`][] package. When passing an
asynchronous iterator to `mapBundleAsync`, wrap it in `CachedAsyncIterable`.
This allows multiple calls to `mapContext*` without advancing and eventually
depleting the iterator.

The API reference is available at
https://projectfluent.org/fluent.js/sequence.

[`cached-iterable`]: https://www.npmjs.com/package/cached-iterable

---
_Source: https://npm.io/package/@fluent/sequence · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
