lingui-string-validation

1.1.0 • Public • Published

lingui-string-validation

npm version Coverage Status license mit circle ci

Check a string is a valid jsLingui string or not (compare with jsLingui minimal format key).

Dependencies

  • lodash
    • Sorry for that, it will be removed in next version

Usage

  • Install
yarn add lodash lingui-string-validation
  • Usage
  /**
   * -1: bad key
   * 0: bad text
   * 1: valid text
   * 2: empty text
   */
 
import checkI18nString from 'lingui-string-validation'
// const lingui-string-validation = require('lingui-string-validation').default
 
const linguiKey = '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>'
const badKey = 'This is a bad {key'
 
checkI18nString(badKey, '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>') // -1
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}</1><2>visit counts: {0}</2></0>') // 1
checkI18nString(linguiKey, '<0><2>觀看次數:{0}</2>, 這是一段有<1>變數</1>的文字</0>') // 1
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}<1><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <3>{variable}</3><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <1>{different}</1><2>visit counts: {0}</2></0>') // 0
checkI18nString(linguiKey, '<0>This is a text with <1>{variable}</1><2>visit counts: 0}</2></0>') // 0
checkI18nString(linguiKey, '') // 2

Readme

Keywords

Package Sidebar

Install

npm i lingui-string-validation

Weekly Downloads

5

Version

1.1.0

License

MIT

Unpacked Size

17.5 kB

Total Files

6

Last publish

Collaborators

  • chiahao