Skip to content

CategoryToken (EN)

bhsd edited this page Jan 15, 2024 · 12 revisions

Other Languages

Introduction

Category.

✅ Available in the Mini and Browser versions.

Properties

name

Expand

type: string
Name of the category, read-only.

// name
var {firstChild} = Parser.parse('[[category:a]]');
assert.strictEqual(firstChild.name, 'Category:A');

link

Expand

type: string
Full link.

// link
var {firstChild} = Parser.parse('[[category:a]]');
assert.deepStrictEqual({...firstChild.link}, {
	valid: true,
	ns: 14,
	fragment: undefined,
	interwiki: '',
});
firstChild.link = 'category:b';
assert.equal(firstChild, '[[category:b]]');

sortkey

Expand

type: string
Sort key.

// sortkey
var {firstChild} = Parser.parse('[[category:a|*]]');
assert.strictEqual(firstChild.sortkey, '*');
firstChild.sortkey = 'b';
assert.equal(firstChild, '[[category:a|b]]');

Methods

lint

✅ Expand

returns: LintError[]
Report potential grammar errors.

// lint
var {firstChild} = Parser.parse('[[category:a#]]');
assert.deepStrictEqual(firstChild.lint(), [
	{
		severity: 'error',
		message: 'useless fragment',
		startLine: 0,
		startCol: 2,
		startIndex: 2,
		endLine: 0,
		endCol: 13,
		endIndex: 13,
	}
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode
var {firstChild} = Parser.parse('[[category:a#]]');
assert.deepStrictEqual(firstChild.cloneNode(), firstChild);

setTarget

Expand

param: string category target
Set the category target.

// setTarget
var {firstChild} = Parser.parse('[[category:a]]');
firstChild.setTarget('category:b');
assert.equal(firstChild, '[[category:b]]');

setSortkey

Expand

param: string sort key
Set the sort key.

// setSortkeyvar
var {firstChild} = Parser.parse('[[category:a]]');
firstChild.setSortkey('b');
assert.equal(firstChild, '[[category:a|b]]');
Clone this wiki locally