Skip to content

ConverterFlagsToken (EN)

Bhsd edited this page Dec 6, 2024 · 10 revisions
Table of Contents

Other Languages

Introduction

Flags of language conversion.

✅ Available in the Mini and Browser versions.

Properties

flags

Expand

type: Set<string>
All conversion flags.

// flags (main)
var flags = Parser.parse('-{H|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.flags, new Set(['H']));
flags.flags = new Set(['R']);
assert.equal(flags, 'R');

Methods

getUnknownFlags

✅ Expand

returns: Set<string>
Get unknown conversion flags.

// getUnknownFlags
var flags = Parser.parse('-{{{{a}}}|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.getUnknownFlags(), new Set(['{{{a}}}']));

getVariantFlags

✅ Expand

returns: Set<string>
Get conversion flags of language variants.

// getVariantFlags
var flags = Parser.parse('-{zh-cn|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.getVariantFlags(), new Set(['zh-cn']));

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var flags = Parser.parse('-{h|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.lint(), [
	{
		rule: 'no-ignored',
		severity: 'error',
		message: 'invalid conversion flag',
		startLine: 0,
		startCol: 2,
		startIndex: 2,
		endLine: 0,
		endCol: 3,
		endIndex: 3,
		fix: {
			range: [2, 3],
			text: 'H',
			desc: 'uppercase',
		},
	},
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode (main)
var flags = Parser.parse('-{}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.cloneNode(), flags);

getAllFlags

Expand

returns: Set<string>
Get all conversion flags.

// getAllFlags (main)
var flags = Parser.parse('-{A|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.getAllFlags(), new Set(['A']));

getFlagTokens

Expand

param: string conversion flag
returns: Token[]
Get conversion flag tokens.

// getFlagTokens (main)
var flags = Parser.parse('-{A|}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.getFlagTokens('A'), [flags.firstChild]);

getEffectiveFlags

Expand

returns: Set<string>
Get effective conversion flags.

// getEffectiveFlags (main)
var flags = Parser.parse('-{}-').querySelector('converter-flags');
assert.deepStrictEqual(flags.getEffectiveFlags(), new Set(['S']));

hasFlag

Expand

param: string conversion flag
returns: boolean
Whether it has a specific conversion flag.

// hasFlag (main)
var flags = Parser.parse('-{R|}-').querySelector('converter-flags');
assert(flags.hasFlag('R'));
flags.firstChild.replaceChildren('H');
assert(!flags.hasFlag('R'));
assert(flags.hasFlag('H'));

hasEffectiveFlag

Expand

param: string conversion flag
returns: boolean
Whether it has a specific effective conversion flag.

// hasEffectiveFlag (main)
var flags = Parser.parse('-{}-').querySelector('converter-flags');
assert(flags.hasEffectiveFlag('S'));

removeFlag

Expand

param: string conversion flag
Remove a specific conversion flag.

// removeFlag (main)
var flags = Parser.parse('-{R|}-').querySelector('converter-flags');
flags.removeFlag('R');
assert.equal(flags, '');

setFlag

Expand

param: string conversion flag
Add a specific conversion flag.

// setFlag (main)
var flags = Parser.parse('-{}-').querySelector('converter-flags');
flags.setFlag('R');
assert.equal(flags, 'R');

toggleFlag

Expand

param: string conversion flag
Toggle a specific conversion flag.

// toggleFlag (main)
var flags = Parser.parse('-{R|}-').querySelector('converter-flags');
flags.toggleFlag('R');
flags.toggleFlag('D');
assert.equal(flags, 'D');
Clone this wiki locally