@theopenweb/rubifyer

1.0.0 • Public • Published

Description

Simple library for rubifying(Add ruby characters/tags) the page. Goal is to simply get mapped ruby characters from API and display for words in current page.

Usage

npm install @theopenweb/rubifyer
import Rubifyer from './index.js'

const dictionary = './dictionary.json' // URL
// const dictionary = { "characters": [ { "char": "完" }, { "char": "璧" } ], "words": [ { "str": "完璧", "ruby": "カンペキ" } ] } // OBJECT
const rubifyer = new Rubifyer({ dictionaries: [dictionary] }) // Partial<RubifyerSettings>
rubifyer.awaitLoad().then(async () => {

    /*
    // RubifyerSettings:
    {
        dictionaries: [],
        dictionary: {},
        format: "object",
        serialization: "json",
        formatConstants: {
            FULL: "full",
            OBJECT: "object",
            SINGLE: "single"
        },
        serializationConstants: {
            JSON: "json",
            STRING: "string"
        }
    }
    */ 

    rubifyer.rubifyPage({ topElement: document })
    rubifyer.derubifyPage({ topElement: document })
    await rubifyer.applySettings(settings) // RubifyerSettings
    rubifyer.clearSettings()
    rubifyer.rubifyElement(element)
    rubifyer.derubifyElement(element)
})

Test

npx http-server ./
# http://localhost:8080

Localization

Package Sidebar

Install

npm i @theopenweb/rubifyer

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

21.5 kB

Total Files

7

Last publish

Collaborators

  • theopenweb_jp