mediawiki-title
Advanced tools
Comparing version 0.5.3 to 0.5.4
@@ -211,3 +211,3 @@ "use strict"; | ||
function _splitNamespace(title, siteInfo) { | ||
function _splitNamespace(title, siteInfo, defaultNs) { | ||
var prefixRegex = /^(.+?)_*:_*(.*)$/; | ||
@@ -227,3 +227,3 @@ var match = title.match(prefixRegex); | ||
title: title, | ||
namespace: Namespace.main(siteInfo) | ||
namespace: (defaultNs !== undefined) ? defaultNs : Namespace.main(siteInfo) | ||
}; | ||
@@ -316,6 +316,7 @@ } | ||
* @param {SiteInfo} siteInfo The site information. | ||
* @param {Namespace|number} defaultNs A default namespace. | ||
* | ||
* @returns {Title} The resulting title object. | ||
*/ | ||
Title.newFromText = function(title, siteInfo) { | ||
Title.newFromText = function(title, siteInfo, defaultNs) { | ||
if (typeof title !== 'string') { | ||
@@ -351,3 +352,7 @@ throw new TypeError('Invalid type of title parameter. Must be a string'); | ||
var result = _splitNamespace(title, siteInfo); | ||
defaultNs = defaultNs === undefined ? defaultNs : | ||
defaultNs.constructor.name === 'Namespace' ? | ||
defaultNs : new Namespace(defaultNs, siteInfo); | ||
var result = _splitNamespace(title, siteInfo, defaultNs); | ||
if (result.namespace.isTalk()) { | ||
@@ -354,0 +359,0 @@ _checkTalkNamespace(result.title, siteInfo); |
{ | ||
"name": "mediawiki-title", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "Title normalization library for mediawiki", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -129,3 +129,3 @@ # 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) | ||
* _static_ | ||
* [.newFromText(title, siteInfo)](#Title.newFromText) ⇒ <code>[Title](#Title)</code> | ||
* [.newFromText(title, siteInfo, defaultNs)](#Title.newFromText) ⇒ <code>[Title](#Title)</code> | ||
@@ -165,3 +165,3 @@ <a name="new_Title_new"></a> | ||
### Title.newFromText(title, siteInfo) ⇒ <code>[Title](#Title)</code> | ||
### Title.newFromText(title, siteInfo, defaultNs) ⇒ <code>[Title](#Title)</code> | ||
Normalize a title according to the rules of <code>siteInfo</code> | ||
@@ -168,0 +168,0 @@ |
@@ -217,2 +217,24 @@ 'use strict'; | ||
describe('Defaults', function() { | ||
var testCases = [ | ||
[ undefined, 'Example.svg', 'Example.svg'], | ||
[ 0, 'Example.svg', 'Example.svg'], | ||
[ 6, 'Example.svg', 'File:Example.svg'], | ||
[ undefined, 'File:Example.svg', 'File:Example.svg'], | ||
[ 6, 'File:Example.svg', 'File:Example.svg'], | ||
[ 2, 'File:Example.svg', 'File:Example.svg'], | ||
]; | ||
testCases.forEach(function (test) { | ||
it('For ns:' + test[0] + ' should default ' + test[1] + ' to ' + test[2], function() { | ||
return getSiteInfo('en.wikipedia.org') | ||
.then(function(siteInfo) { | ||
return Title.newFromText(test[1], siteInfo, test[0]).getPrefixedDBKey(); | ||
}) | ||
.then(function(res) { | ||
assert.deepEqual(res, test[2]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('Utilities', function () { | ||
@@ -219,0 +241,0 @@ var data = [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45505
929