ConverterRuleToken (EN) - bhsd-harry/wikiparser-node GitHub Wiki
Table of Contents
A single conversion rule. This class inherits all the properties and methods of the Token class which are not repeated here.
🌐 Available in the Browser version.
🌐 Expand
type: string
The language variant.
// variant (print)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.strictEqual(rule.variant, 'zh-hans');
// variant (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
rule.variant = 'zh-hant';
assert.equal(rule, '繁體=>zh-hant:繁体');
Expand
type: boolean
Whether it is a unidirectional conversion.
// unidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.ok(rule.unidirectional);
rule.unidirectional = false;
assert.equal(rule, 'zh-hans:繁体');
Expand
type: boolean
Whether it is a bidirectional conversion.
// bidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.ok(!rule.bidirectional);
rule.bidirectional = true;
assert.equal(rule, 'zh-hans:繁体');
🌐 Expand
Save the syntax tree as JSON.
// json
var rule = Parser.parse('-{a}-').querySelector('converter-rule');
assert.equal(rule, 'a');
assert.deepStrictEqual(rule.json(), {
range: [2, 3],
type: 'converter-rule',
variant: '',
childNodes: [
{
range: [2, 3],
type: 'converter-rule-to',
childNodes: [
{
range: [2, 3],
data: 'a',
},
],
},
],
});
Expand
returns: this
Deep clone the node.
// cloneNode (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
assert.deepStrictEqual(rule.cloneNode(), rule);
Expand
修改为不转换。
// noConvert (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁體}-').querySelector('converter-rule');
rule.noConvert();
assert.equal(rule, '繁體');
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:繁体');
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:繁體');
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:繁体');
Expand
param: string
Alias for setFrom method.
Expand
Change to bidirectional conversion.
// makeBidirectional (main)
var rule = Parser.parse('-{繁體=>zh-hans:繁体}-').querySelector('converter-rule');
rule.makeBidirectional();
assert.equal(rule, 'zh-hans:繁体');