2.8.3 • Published 5 years ago

knayi-myscript v2.8.3

Weekly downloads
97
License
MIT
Repository
github
Last release
5 years ago

Knayi Myanmar Script

NPM version

Standalone Myanmar languages js library, to build Myanmar Unicode standard web.

Announce on breaking API changes from 2.4.2 -> 2.5.0

  • All throw Error are now become console.warn and console.error
  • If content not found happens, #fontConvert, #spellingCheck, #syllBreak all return empty string
  • If content not found happens, #fontDetect return fallback_font_type or 'en'
  • You can set silent by setting knayi.setGlobalOptions({silent_mode: true})

Node Version

  • Required node version >= 4
    Note: From version >=2.3.0 build step will only support for node >=6

Features

  • Detector (Unicode and Zawgyi) Detection now
  • Converter (Unicode and Zawgyi)
  • SyallBreak (Unicode and Zawgyi)
  • Spelling Check (Unicode and Zawgyi)
  • Truncate (Unicode and Zawgyi)
  • Normalization (Unicode only)

Installation

Using npm

npm install knayi-myscript --save

Using yran

yarn add knayi-myscript

Using CDN

<script src="https://unpkg.com/knayi-myscript@latest/dist/knayi-myscript.min.js"></script>

API

Method NameArgumentsReturnNote
fontDetectcontent: String(require), fallbackFontType:, options fontName(options), options: Object(options)StringFont Detector, it will detect unicode/zawgyi of the content Text. If nothing is matched or possibility are equal, it will return as 'zawgyi' or specified font type in *fallbackFontType, options* params.
fontConvertcontent: String(require),targetFontType: fontName(require),orignalFontType: fontName(optional)StringConverting font to target font type. This method need spelling fix, so it gonna use spellingFix in default. convertFrom will be detect by fontDetect when you don't described. fontName must be one of unicode or zawgyi.
syllBreakcontent: String(require),fontType: fontName(optional),breakPoint: String(optional)StringTo make systematic word break of Myanmar text. convertFrom will be detect by fontDetect when you don't described. fontName must be one of unicode or zawgyi.
spellingFixcontent: String(require),fontType: fontName(optional)StringconvertFrom will be detect by fontDetect when you don't described. It fix spelling on Myanmar Text. fontName must be one of unicode or zawgyi.
truncatecontent: String(requre),options: ObjectStringLike lodash.truncate, it truncate word syllable and space. Default truncate length is 30 and you can change it in options.length
normalizecontent: String(requre)StringNormzliation solve some typing errors. Unlike spellingFix this offer more appropriate way of doing so. But this function can only solve some level of normalization.

Usage

// ES5 Way
var knayi = require('knayi-myscript')

// ES6 Way
import knayi from 'knayi-myscript'

Example

  • fontDetect(content [, fallbackFontType , options])
knayi.fontDetect('မဂၤလာပါ') // zawgyi
knayi.fontDetect('မင်္ဂလာပါ') // unicode
knayi.fontConvert('မဂၤလာပါ', 'unicode', 'zawgyi') // မင်္ဂလာပါ
knayi.fontConvert('မဂၤလာပါ', 'unicode') // မင်္ဂလာပါ
knayi.syllBreak('မင်္ဂလာပါ', null, '$$')
// output: 'မင်္ဂလာ$$ပါ'
knayi.syllBreak('မင်္ဂလာပါ')
// output: 'မင်္ဂလာ\u200bပါ'
knayi.spellingFix('မင်္ဂလာာပါါ') 
// output: 'မင်္ဂလာပါ'
knayi.truncate('အာယုဝဍ်ဎနဆေးညွှန်းစာကို ဇလွန်ဈေးဘေးဗာဒံပင်ထက် အဓိဋ္ဌာန်လျက် ဂဃနဏဖတ်ခဲ့သည်။', { length: 30, omission: '...' });
// output: "အာယုဝဍ်ဎနဆေးညွှန်းစာကို ဈေး..."

options of truncate

  • length: Number default is 30
  • omission:String default is '...'
  • fontType: String it automatically detect if it not specified

  • normalize(content)

knayi.normalize('မိြုင်မိြုင်\nဆိုင်ဆုိင်')
// output: မြိုင်မြိုင်\nဆိုင်ဆိုင်

Using googlei18n/myanmartools in detector.js

In default, knayi use own logic font dector rules, but you can choose knayi to use googlei18n/myanmartoolsTo do that, setuse_myanmartoolsoption to true. By defaultuse_myanmartoolsoption is set tofalse`.

Example::

// Add options for single process
knayi.fontDetect('မဂၤလာပါ', null, {use_myanmartools: true}) // this will use myanmartools
knayi.fontDetect('မင်္ဂလာပါ') // this will use default

// OR set for whole project
knayi.setGlobalOptions({
  detector: {
    use_myanmartools: true
  }
})

You can also set Probability threshold percentages of zawgyi predicting by myanmartools_zg_threshold as [lower, higher]. Which mean if predicting result of myanmartools is < 0.05 detector.js assume as unicode or > 0.95 it assume as zawgyi.

knayi.fontDetect('မင်္ဂလာပါ', null, {
  use_myanmartools: true,
  myanmartools_zg_threshold: [0.05, 0.95]
})

Debugging of font converting

Visit http://tools.kny.co/knayi-myscript#debug-mode and select text to track how converting happened in background.

Build

  • Required node >=6
  • npm run build
    To build production run webpack -p

License

MIT

2.8.3

5 years ago

2.8.2

5 years ago

2.8.1

5 years ago

2.8.0

5 years ago

2.7.3

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.7.0-0

5 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.9

6 years ago

2.5.8

6 years ago

2.5.7

6 years ago

2.5.6

6 years ago

2.5.5

6 years ago

2.5.4

6 years ago

2.5.3

6 years ago

2.5.2

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

8 years ago

2.0.0

8 years ago

1.0.13

8 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago