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 - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

5

.jscs.json

@@ -15,3 +15,6 @@ {

"requireCapitalizedComments": null,
"maximumLineLength": 100,
"maximumLineLength": {
"value": 100,
"allExcept": [ "urlComments" ]
},
"validateQuoteMarks": null,

@@ -18,0 +21,0 @@ "requireTrailingComma": null,

67

lib/index.js

@@ -18,10 +18,15 @@ "use strict";

* Information about a wikimedia site required to make correct
* normalization.
* normalization. This information matches the format used by the
* <a href="https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=general%7Cnamespaces%7Cnamespacealiases">PHP API response</a>,
* however not all of the fields are required for library operation.
*
* The list of required properties is documented here, others can be removed.
*
* @typedef SiteInfo
* @type Object
* @property {string} lang Site language code.
* @property {string} legaltitlechars A perl-like regex for characters
* @property {Object} general General information about the site
* @property {string} general.lang Site language code.
* @property {string} general.legaltitlechars A perl-like regex for characters
* allowed in the page title.
* @property {string} case Whether to capitalize the first letter of the title.
* @property {string} general.case Whether to capitalize the first letter of the title.
* Could be obtained from the `general` section of the `siteInfo` php API response.

@@ -115,2 +120,44 @@ * @property {Object} namespaces Site namespaces info in the same format as

nameSpaceIds.Image = nameSpaceIds.File;
/**
* Checks whether namespace is `Media`
*
* @method
* @name Namespace.prototype#isMedia
* @return {boolean}
*/
/**
* Checks whether namespace is `Special`
*
* @method
* @name Namespace.prototype#isSpecial
* @return {boolean}
*/
/**
* Checks whether namespace is `Main`
*
* @method
* @name Namespace.prototype#isMain
* @return {boolean}
*/
/**
* Checks whether namespace is `Talk`
*
* @method
* @name Namespace.prototype#isTalk
* @return {boolean}
*/
/**
* Checks whether namespace is `UserTalk`
*
* @method
* @name Namespace.prototype#isUserTalk
* @return {boolean}
*/
nameSpaceIds.ImageTalk = nameSpaceIds.FileTalk;

@@ -155,7 +202,7 @@

function _capitalizeTitle(result, siteInfo) {
if (siteInfo.case === 'first-letter') {
if (result.title[0] === 'i' && (siteInfo.lang === 'az'
|| siteInfo.lang === 'tr'
|| siteInfo.lang === 'kaa'
|| siteInfo.lang === 'kk')) {
if (siteInfo.general.case === 'first-letter') {
if (result.title[0] === 'i' && (siteInfo.general.lang === 'az'
|| siteInfo.general.lang === 'tr'
|| siteInfo.general.lang === 'kaa'
|| siteInfo.general.lang === 'kk')) {
result.title = 'İ' + result.title.substr(1);

@@ -190,3 +237,3 @@ } else if (!/^[A-Z]/.test(result.title)) {

function _checkLegalTitleCharacters(title, siteInfo) {
var match = title.match(_createInvalidTitleRegex(siteInfo.legaltitlechars));
var match = title.match(_createInvalidTitleRegex(siteInfo.general.legaltitlechars));
if (match) {

@@ -193,0 +240,0 @@ throw new utils.TitleError({

{
"name": "mediawiki-title",
"version": "0.3.3",
"version": "0.4.0",
"description": "Title normalization library for mediawiki",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

# mediawiki-title [![npm version](https://badge.fury.io/js/mediawiki-title.svg)](https://badge.fury.io/js/mediawiki-title) [![Build Status](https://travis-ci.org/wikimedia/mediawiki-title.svg?branch=master)](https://travis-ci.org/wikimedia/mediawiki-title) [![Coverage Status](https://coveralls.io/repos/github/wikimedia/mediawiki-title/badge.svg?branch=master)](https://coveralls.io/github/wikimedia/mediawiki-title?branch=master) [![Dependencies](https://david-dm.org/wikimedia/mediawiki-title.svg?branch=master)](https://david-dm.org/wikimedia/mediawiki-title?branch=master)
Mediawiki title normalizetion, that conforms to the normalization rules used in [MediaWiki Core](https://www.mediawiki.org/wiki/API:Query#Title_normalization).
Mediawiki title normalization, that conforms to the normalization rules used in [MediaWiki Core](https://www.mediawiki.org/wiki/API:Query#Title_normalization).
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.
and applying wiki-specific capitalization rules. The namespace name is converted to a localized canonical name.

@@ -21,3 +21,6 @@ ## Classes

<dd><p>Information about a wikimedia site required to make correct
normalization.</p>
normalization. This information matches the format used by the
<a href="https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=general%7Cnamespaces%7Cnamespacealiases">PHP API response</a>,
however not all of the fields are required for library operation.</p>
<p>The list of required properties is documented here, others can be removed.</p>
</dd>

@@ -27,2 +30,3 @@ </dl>

<a name="Namespace"></a>
## Namespace

@@ -34,7 +38,7 @@ **Kind**: global class

* _instance_
* [.isSpecial()](#Namespace+isSpecial) ⇒ <code>boolean</code>
* [.isMain()](#Namespace+isMain) ⇒ <code>boolean</code>
* [.isTalk()](#Namespace+isTalk) ⇒ <code>boolean</code>
* [.isUser()](#Namespace+isUser) ⇒ <code>boolean</code>
* [.isUserTalk()](#Namespace+isUserTalk) ⇒ <code>boolean</code>
* [.isMedia()](#Namespace++isMedia) ⇒ <code>boolean</code>
* [.isSpecial()](#Namespace++isSpecial) ⇒ <code>boolean</code>
* [.isMain()](#Namespace++isMain) ⇒ <code>boolean</code>
* [.isTalk()](#Namespace++isTalk) ⇒ <code>boolean</code>
* [.isUserTalk()](#Namespace++isUserTalk) ⇒ <code>boolean</code>
* [.getNormalizedText()](#Namespace+getNormalizedText) ⇒ <code>string</code>

@@ -46,2 +50,3 @@ * _static_

<a name="new_Namespace_new"></a>
### new Namespace(id, siteInfo)

@@ -56,28 +61,34 @@ Represents a wiki namespace

<a name="Namespace+isSpecial"></a>
<a name="Namespace++isMedia"></a>
### namespace.isMedia() ⇒ <code>boolean</code>
Checks whether namespace is `Media`
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace++isSpecial"></a>
### namespace.isSpecial() ⇒ <code>boolean</code>
Checks whether namespace is `Special`.
Checks whether namespace is `Special`
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace+isMain"></a>
<a name="Namespace++isMain"></a>
### namespace.isMain() ⇒ <code>boolean</code>
Checks whether namespace is `Main`.
Checks whether namespace is `Main`
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace+isTalk"></a>
<a name="Namespace++isTalk"></a>
### namespace.isTalk() ⇒ <code>boolean</code>
Checks whether namespace is `Talk`.
Checks whether namespace is `Talk`
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace+isUser"></a>
### namespace.isUser() ⇒ <code>boolean</code>
Checks whether namespace is `User`.
<a name="Namespace++isUserTalk"></a>
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace+isUserTalk"></a>
### namespace.isUserTalk() ⇒ <code>boolean</code>
Checks whether namespace is `User_Talk`.
Checks whether namespace is `UserTalk`
**Kind**: instance method of <code>[Namespace](#Namespace)</code>
<a name="Namespace+getNormalizedText"></a>
### namespace.getNormalizedText() ⇒ <code>string</code>

@@ -88,2 +99,3 @@ Get the canonical name string for this namespace.

<a name="Namespace.fromText"></a>
### Namespace.fromText(text, siteInfo) ⇒ <code>[Namespace](#Namespace)</code> &#124; <code>undefined</code>

@@ -101,2 +113,3 @@ Creates a namespace instance from namespace text or a namespace alias

<a name="Namespace.main"></a>
### Namespace.main(siteInfo) ⇒ <code>[Namespace](#Namespace)</code>

@@ -112,2 +125,3 @@ Creates a namespace object for a `Main` namespace.

<a name="Title"></a>
## Title

@@ -120,2 +134,3 @@ **Kind**: global class

* [.getPrefixedDBKey()](#Title+getPrefixedDBKey) ⇒ <code>string</code>
* [.getFragment()](#Title+getFragment) ⇒ <code>string</code> &#124; <code>undefined</code>
* [.getNamespace()](#Title+getNamespace) ⇒ <code>[Namespace](#Namespace)</code>

@@ -126,2 +141,3 @@ * _static_

<a name="new_Title_new"></a>
### new Title(key, namespace, siteInfo, [fragment])

@@ -139,2 +155,3 @@ Creates a new title object with article the dbKey and namespace

<a name="Title+getPrefixedDBKey"></a>
### title.getPrefixedDBKey() ⇒ <code>string</code>

@@ -144,3 +161,10 @@ Returns the normalized article title and namespace.

**Kind**: instance method of <code>[Title](#Title)</code>
<a name="Title+getFragment"></a>
### title.getFragment() ⇒ <code>string</code> &#124; <code>undefined</code>
Returns the normalized fragment part of the original title
**Kind**: instance method of <code>[Title](#Title)</code>
<a name="Title+getNamespace"></a>
### title.getNamespace() ⇒ <code>[Namespace](#Namespace)</code>

@@ -151,2 +175,3 @@ Returns the namespace of an article.

<a name="Title.newFromText"></a>
### Title.newFromText(title, siteInfo) ⇒ <code>[Title](#Title)</code>

@@ -164,6 +189,11 @@ Normalize a title according to the rules of <domain>

<a name="SiteInfo"></a>
## SiteInfo : <code>Object</code>
Information about a wikimedia site required to make correct
normalization.
normalization. This information matches the format used by the
<a href="https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&siprop=general%7Cnamespaces%7Cnamespacealiases">PHP API response</a>,
however not all of the fields are required for library operation.
The list of required properties is documented here, others can be removed.
**Kind**: global typedef

@@ -174,8 +204,10 @@ **Properties**

| --- | --- | --- |
| lang | <code>string</code> | Site language code. |
| legaltitlechars | <code>string</code> | A perl-like regex for characters allowed in the page title. |
| case | <code>string</code> | Whether to capitalize the first letter of the title. Could be obtained from the `general` section of the `siteInfo` php API response. |
| general | <code>Object</code> | General information about the site |
| general.lang | <code>string</code> | Site language code. |
| general.legaltitlechars | <code>string</code> | A perl-like regex for characters allowed in the page title. |
| general.case | <code>string</code> | Whether to capitalize the first letter of the title. Could be obtained from the `general` section of the `siteInfo` php API response. |
| namespaces | <code>Object</code> | Site namespaces info in the same format as returned by PHP api. |
| namespacealiases | <code>Object</code> | Site namespace aliases in the same format as returned by PHP api. |
## Usage

@@ -189,4 +221,7 @@

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

@@ -207,3 +242,3 @@ "0": {

For bug reporting please use [Phabricator](https://phabricator.wikimedia.org/tag/services/) ]
and mark the bugs with `Servises` label or contuct directly in IRC in the [#wikimedia-services](http://webchat.freenode.net/?channels=wikimedia-services) channel.
and mark the bugs with `Servises` label or contact directly in IRC in the [#wikimedia-services](http://webchat.freenode.net/?channels=wikimedia-services) channel.

@@ -29,9 +29,3 @@ 'use strict';

.then(function(res) {
return {
lang: res.body.query.general.lang,
legaltitlechars: res.body.query.general.legaltitlechars,
case: res.body.query.general.case,
namespaces: res.body.query.namespaces,
namespacealiases: res.body.query.namespacealiases
}
return res.body.query;
});

@@ -38,0 +32,0 @@ return siteInfoCache[domain];

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