ConverterRuleToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki

Table of Contents

Other Languages

Introduction

A single conversion rule.

All of the following properties and methods are not available in the Mini and Browser versions.

Properties

variant

Expand

type: string
The language variant.

// variant (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.strictEqual(rule.variant, 'zh-hans');
rule.variant = 'zh-hant';
assert.equal(rule, '繁體=>zh-hant:繁体');

unidirectional

Expand

type: boolean
Whether it is a unidirectional conversion.

// unidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert(rule.unidirectional);
rule.unidirectional = false;
assert.equal(rule, 'zh-hans:繁体');

bidirectional

Expand

type: boolean
Whether it is a bidirectional conversion.

// bidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert(!rule.bidirectional);
rule.bidirectional = true;
assert.equal(rule, 'zh-hans:繁体');

Methods

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.deepStrictEqual(rule.cloneNode(), rule);

noConvert

Expand

修改为不转换。

// noConvert (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁體}-').querySelector('converter-rule');
rule.noConvert();
assert.equal(rule, '繁體');

setTo

Expand

param: string target of conversion
Set the target of conversion.

// setTo (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁體}-').querySelector('converter-rule');
rule.setTo('繁体');
assert.equal(rule, '繁體=>zh-hans:繁体');

setVariant

Expand

param: string language variant
Set the language variant.

// setVariant (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁體}-').querySelector('converter-rule');
rule.setVariant('zh-cn');
assert.equal(rule, '繁體=>zh-cn:繁體');

setFrom

Expand

param: string source of conversion
Set the source of conversion.

// setFrom (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
rule.setFrom('正體');
assert.equal(rule, '正體=>zh-hans:繁体');

makeUnidirectional

Expand

param: string
Alias for setFrom method.

makeBidirectional

Expand

Change to bidirectional conversion.

// makeBidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
rule.makeBidirectional();
assert.equal(rule, 'zh-hans:繁体');
⚠️ **GitHub.com Fallback** ⚠️