Gathering detailed insights and metrics for format-message-interpret
Gathering detailed insights and metrics for format-message-interpret
Gathering detailed insights and metrics for format-message-interpret
Gathering detailed insights and metrics for format-message-interpret
npm install format-message-interpret
Typescript
Module System
Node Version
NPM Version
97.2
Supply Chain
91.7
Quality
80.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
6,990,230
Last Day
3,990
Last Week
21,741
Last Month
90,372
Last Year
861,548
MIT License
205 Stars
496 Commits
37 Forks
4 Watchers
24 Branches
18 Contributors
Updated on Sep 25, 2024
Minified
Minified + Gzipped
Latest Version
6.2.4
Package Id
format-message-interpret@6.2.4
Unpacked Size
29.56 kB
Size
6.45 kB
File Count
6
NPM Version
lerna/3.13.3/node@v16.9.1+arm64 (darwin)
Node Version
16.9.1
Cumulative downloads
Total Downloads
Last Day
45.9%
3,990
Compared to previous day
Last Week
-0.5%
21,741
Compared to previous week
Last Month
9.1%
90,372
Compared to previous month
Last Year
-37.1%
861,548
Compared to previous year
2
Convert format-message-parse ast to a function
Turns a compact format-message ast:
1[ "You have ", [ "numBananas", "plural", 0, { 2 "=0": [ "no bananas" ], 3 "one": [ "a banana" ], 4 "other": [ [ '#' ], " bananas" ] 5} ], " for sale." ]
into a function:
1format({ numBananas:0 }) 2//-> "You have no bananas for sale."
npm install format-message-interpret --save
1import parse from 'format-message-parse' 2import interpret from 'format-message-interpret' 3 4interpret('en', parse('Hello, {name}!'))({ name: 'Jane' })
interpret(locales: string | string[], ast: AST, types?: Types)
Generate a function from an ast
, using the formatting rules of the locales
that accepts an arguments object, and returns a string. You can optionally pass custom types
. Any non-standard type found in ast
without a corresponding formatter in types
will be treated as a simple string type.
1type Types = { 2 [type: string]: (placeholder: string[], locales: string | string[]) => 3 (value: any, args: Object) => string 4}
types
is an object with each key being the name of the type as it appears in the message pattern. Each value is a function that takes the locales
, and the node
from the ast (like [ 'a', 'mytype', 'style' ]
), and it returns a function that will be called with the specific value
, and the complete arguments object. If the custom type was defined with sub-messages, those will already be converted to functions meant to be called with args
.
interpret.toParts(locales: string | string[], ast: AST, types?: Types)
Like, interpret
, interpretToParts
will generate a function accepting the message arguments. However, it will return an array of message parts, instead of a string. This is intended to help generate rich messages.
1interpret.toParts('en', parse('a {b} c'))({ b: 1 }) // [ 'a ', 1, ' c' ]
2interpret.toParts('en', parse('Click {a, element, children {here}}'), {
3 element: (locales, [ id, type, props ]) =>
4 (fn, args) => fn(props.children(args))
5})({ a: children => <a>{children}</a> })
6// [ 'Click ', <a>here</a> ]
This software is free to use under the MIT license. See the LICENSE-MIT file for license text and copyright information.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/10 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
123 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More