
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
icu-validator
Advanced tools
Check if a text conforms to ICU format - supports individual string, JSON files or folders contaning JSON files
Validate a data source if all strings in the data source conforms to ICU standard. Supports -
Install using yarn -
yarn add icu-validator -D
or using npm
npm install icu-validator --save-dev
// Using ESM
import { validate, validateFile, validateDirectory } from 'icu-validator';
// Using CJS
const { validate, validateFile, validateDirectory } = require('icu-validator');
const { validate } = require('icu-validator');
const validationResult = validate('Hello {{name}}, how are you?');
/**
* {
* "__icu_validator_error":true,
* "result": {
* "errorMessage":"MALFORMED_ARGUMENT",
* "originalMessage":"Hello {{name}}, how are you?",
* "location": {
* "start": { "offset":6,"line":1,"column":7 },
* "end": { "offset":7,"line":1,"column":8 }
* }
* }
* }
**/
const validationResult = validate('Hello {name}, how are you?');
/**
* { "__icu_validator_error": false }
**/
You can pretty print the errors by passing a flag prettyPrint: true
const validationResult = validate('Hello {{name}}, how are you?', { prettyPrint: true });
const obj = {
"welcome": "Hello {name}, how are you?",
"examples": {
"pluralization": "Hi {name}, you have {{numProducts, plural, =0 {no items} =1 {one item} other {# items}} in cart"
}
};
validate(obj, { prettyPrint: true });
/**
Invalid ICU string :- Hi {name}, you have {{numProducts, plural, =0 {no items} =1 {one item} other {# items}} in cart
Object path :- examples.pluralization
Error :- MALFORMED_ARGUMENT
Location :- {"start":{"offset":20,"line":1,"column":21},"end":{"offset":21,"line":1,"column":22}}
**/
Validate method does accept a file or directory path as first argument. But one very important thing to keep in mind - the validate method is completely sync, so all file & directory read operations will be sync.
It is recommended to use dedicated validateFile
and validateDirectory
async methods.
validateFile(filePath).then((result) => {
console.log(JSON.stringify(result));
});
validateDirectory(directoryPath).then((result) => {
console.log(JSON.stringify(result));
});
Try prettyPrint: true
if you want to show the errors on screen
validate
, validateFile
and validateDirectory
take a 2nd argument - options
to customize the output format and validation rules/
validate(source: string | object, options: object)
validateFile(filePath: string, options: object)
validateDirectory(directoryPath: string, options: object)
Options include -
prettyPrint
- default (false
)Print the validation result and errors in console.
verbose
- default (false
)Provide complete execution logs when printing the results.
ignoreTransTag
- default (false
)If you are using react-i18next
with ICU, you will encounter situations where you need to externalize HTML elements. For react-i18next, the recommended method is Trans component. The externalized string resembles a format - Please click <0>here</0>
. These are usually termed as invalid strings. Use this option if you want to ignore such tags from validation rule.
parseOptions
Under the hood, icu-validator
uses formatjs
parser. You can customize the validation rules by customizing the parser -
ignoreTag
Whether to treat HTML/XML tags as string literal
requiresOtherClause
Should select
, selectordinal
, and plural
arguments always include the other
case clause
shouldParseSkeletons
Whether to parse number/datetime skeleton into Intl.NumberFormatOptions and Intl.DateTimeFormatOptions, respectively.
captureLocation
Capture location info in AST
locale
Instance of Intl.Locale to resolve locale-dependent skeleton
FAQs
Check if a text conforms to ICU format - supports individual string, JSON files or folders contaning JSON files
The npm package icu-validator receives a total of 6,452 weekly downloads. As such, icu-validator popularity was classified as popular.
We found that icu-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.