Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mediawiki-title

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mediawiki-title

Title normalization library for mediawiki

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
increased by200.99%
Maintainers
4
Weekly downloads
 
Created
Source

mediawiki-title npm version Build Status Coverage Status Dependencies

Mediawiki title normalizetion, that conforms to the normalization rules used in MediaWiki Core. In general, the page title is converted to the mediawiki DB key format by trimming spaces, replacing whitespace symbols to underscores and applying wiki-specific capitalizetion rules. The namespace name is converted to a localized canonical name.

Classes

Namespace
Title

Typedefs

SiteInfo : Object

Information about a wikimedia site required to make correct normalization.

Namespace

Kind: global class

new Namespace(id, siteInfo)

Represents a wiki namespace

ParamTypeDescription
idnumberThe namespace identifier
siteInfoSiteInfoThe site metadata information.

namespace.isSpecial() ⇒ boolean

Checks whether namespace is Special.

Kind: instance method of Namespace

namespace.isMain() ⇒ boolean

Checks whether namespace is Main.

Kind: instance method of Namespace

namespace.isTalk() ⇒ boolean

Checks whether namespace is Talk.

Kind: instance method of Namespace

namespace.isUser() ⇒ boolean

Checks whether namespace is User.

Kind: instance method of Namespace

namespace.isUserTalk() ⇒ boolean

Checks whether namespace is User_Talk.

Kind: instance method of Namespace

namespace.getNormalizedText() ⇒ string

Get the canonical name string for this namespace.

Kind: instance method of Namespace

Namespace.fromText(text, siteInfo) ⇒ Namespace | undefined

Creates a namespace instance from namespace text or a namespace alias

Kind: static method of Namespace
Returns: Namespace | undefined - a namespace or undefined if it wasn't found.

ParamTypeDescription
textstringNamespace name text.
siteInfoSiteInfothe site information.

Namespace.main(siteInfo) ⇒ Namespace

Creates a namespace object for a Main namespace.

Kind: static method of Namespace

ParamTypeDescription
siteInfoSiteInfothe site information.

Title

Kind: global class

new Title(key, namespace, siteInfo, [fragment])

Creates a new title object with article the dbKey and namespace

ParamTypeDescription
keystringThe article title in a form of the dbKey.
namespaceNamespace | numberThe article namespace.
siteInfoSiteInfoThe site metadata.
[fragment]stringThe fragment of the title.

title.getPrefixedDBKey() ⇒ string

Returns the normalized article title and namespace.

Kind: instance method of Title

title.getNamespace() ⇒ Namespace

Returns the namespace of an article.

Kind: instance method of Title

Title.newFromText(title, siteInfo) ⇒ Title

Normalize a title according to the rules of

Kind: static method of Title
Returns: Title - The resulting title object.

ParamTypeDescription
titlestringThe page title to normalize.
siteInfoSiteInfoThe site information.

SiteInfo : Object

Information about a wikimedia site required to make correct normalization.

Kind: global typedef
Properties

NameTypeDescription
langstringSite language code.
legaltitlecharsstringA perl-like regex for characters allowed in the page title.
casestringWhether to capitalize the first letter of the title. Could be obtained from the general section of the siteInfo php API response.
namespacesObjectSite namespaces info in the same format as returned by PHP api.
namespacealiasesObjectSite namespace aliases in the same format as returned by PHP api.

Usage

The library returns a Bluebird promise of a normalized title. Wiki-specific rules are fetched from the api, and cached within the Normalizer instance, so reusing the instance is highly recommended.

var result = Title.fromPrefixedText('some_title', {
	lang: 'en',
	legaltitlechars: " %!\"$&'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+",
	namespaces: {
		"0": {
			id: 0,
			case: "first-letter",
			content: "",
			"*": ""
			},
		}
});
console.log(result.getPrefixedDBKey());

Bug reporting

For bug reporting please use Phabricator ] and mark the bugs with Servises label or contuct directly in IRC in the #wikimedia-services channel.

Keywords

FAQs

Package last updated on 08 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc