Comparing version 0.5.0-pre.2 to 0.5.0-pre.3
25
index.js
@@ -345,2 +345,27 @@ var decodeFGHIURL = function(encodedString){ | ||
FidonetURL.prototype.hasFilters = function(){ | ||
if( this.scheme !== 'area' ) return false; | ||
var arrFilters = [ | ||
'msgid', | ||
'time', | ||
'from', | ||
'twit', | ||
'find', | ||
'subj', | ||
'findsb', | ||
'to', | ||
'sender', | ||
'geomark', | ||
'geofrom', | ||
'tag', | ||
'ttop' | ||
]; | ||
for( var i = 0; i < this.optionalParams.length; i++ ){ | ||
if( arrFilters.indexOf(this.optionalParams[i].name) >= 0 ){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
FidonetURL.prototype.errors = { | ||
@@ -347,0 +372,0 @@ NO_SEPARATOR : 'No :// separator in URL!', |
{ | ||
"name": "fghi-url", | ||
"version": "0.5.0-pre.2", | ||
"version": "0.5.0-pre.3", | ||
"description": "FGHI URL parser", | ||
@@ -12,4 +12,4 @@ "main": "index.js", | ||
"pretest": "jshint index.js test/", | ||
"test": "mocha -R spec" | ||
"test": "mocha --reporter spec" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# FGHI URL | ||
## FGHI URL | ||
@@ -9,5 +9,5 @@ This repository contains draft standards of Uniform Resource Locators for the Fidonet Global Hypertext Interface project. | ||
This repository does also contain a JavaScript module (for Node.js) as a proof of concept and a reference implementation. | ||
This repository does also contain a JavaScript module (for Node.js) as a proof of concept and a reference implementation. It requires Node.js version 0.8 (or newer) and npm. An attempt of an npm-driven installation in Node 0.6 (or older) [would fail in 2014](https://github.com/npm/npm/issues/4379) anyway. | ||
# Versions | ||
## Versions | ||
@@ -18,3 +18,3 @@ Both drafts of the standards are “nightly builds” of 0.5pre version, dated 8 Apr 2010 (and after that date any regular updating of the 0.5pre drafts was abandoned). | ||
# Installing the module | ||
## Installing the module | ||
@@ -29,6 +29,10 @@ [![(npm package version)](https://badge.fury.io/js/fghi-url.png)](https://npmjs.org/package/fghi-url) | ||
# Using the module | ||
## Using the module | ||
When you `require()` the installed module, an URL parser function is returned. You may call that function (with some FGHI URL as its only parameter), and it returns an object with properties that correspond to parts of the given URL. | ||
When you `require()` the installed module, an URL parser function is returned. | ||
You may call that function (with some FGHI URL as its only parameter), and it returns an object with properties that correspond to parts of the given URL. | ||
(An URL parser function is actually that object's constructor, but using the word `new` is optional.) | ||
Example: | ||
@@ -38,2 +42,4 @@ | ||
## Properties | ||
The returned object has the following properties: | ||
@@ -49,3 +55,3 @@ | ||
* `optionalParams` — An array of optional parameters encountered in `optionalPart`. Each parameter is an object that has two parameters (`name` and `value`). | ||
* `optionalParams` — An array of optional parameters encountered in `optionalPart`. Each parameter is an object that has two properties (`name` and `value`). | ||
@@ -66,4 +72,12 @@ * `request` — The request (for `faqserv://…` URLs only; empty for URLs of other types). | ||
# Testing the module | ||
The returned object also has the following method: | ||
### hasFilters() | ||
Returns `true` if the object's `scheme` is `"area"` and its `optionalPart` contains at least one filter. | ||
Returns `false` otherwise. For `area://…` URLs it means that the designated object is the whole area(s) unless `objectPath` is given. | ||
## Testing the module | ||
[![(build testing status)](https://travis-ci.org/Mithgol/FGHI-URL.png?branch=master)](https://travis-ci.org/Mithgol/FGHI-URL) | ||
@@ -79,3 +93,3 @@ | ||
# License | ||
## License | ||
@@ -82,0 +96,0 @@ Distribution of the FGHI URL standards is unlimited (see section 1), provided that the text is not altered without notice. |
291
test/test.js
@@ -160,2 +160,293 @@ /*global describe, it */ | ||
}); | ||
}); | ||
describe('URL processing', function(){ | ||
describe("processes 'netmail:' examples (section 6.1)", function(){ | ||
it('section 6.1 initial part', function(){ | ||
var url = FGHIURL('netmail:2:5030/1520.9'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '1520'); | ||
assert.equal(url.stationPoint, '9'); | ||
assert.equal(url.stationDomain, ''); | ||
url = FGHIURL('netmail:2:5063/88'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5063'); | ||
assert.equal(url.stationNode, '88'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
url = FGHIURL('netmail:182:5043/1@forestnet'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '182'); | ||
assert.equal(url.stationNet, '5043'); | ||
assert.equal(url.stationNode, '1'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, 'forestnet'); | ||
}); | ||
it('section 6.1.1', function(){ | ||
var url = FGHIURL('netmail:2:5063/88?to=Mithgol+the+Webmaster'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5063'); | ||
assert.equal(url.stationNode, '88'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'to', | ||
value: 'Mithgol the Webmaster' | ||
}]); | ||
url = FGHIURL('netmail:2:5030/1520.9?to=Trooper'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '1520'); | ||
assert.equal(url.stationPoint, '9'); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'to', | ||
value: 'Trooper' | ||
}]); | ||
url = FGHIURL('netmail:2:50/13?to=Alex%20Kocharin'); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '50'); | ||
assert.equal(url.stationNode, '13'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'to', | ||
value: 'Alex Kocharin' | ||
}]); | ||
}); | ||
it('section 6.1.2', function(){ | ||
var url = FGHIURL( | ||
'netmail:2:5063/88?subject=Is+the+hypertext+Fidonet+ready%3F' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5063'); | ||
assert.equal(url.stationNode, '88'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'subject', | ||
value: 'Is the hypertext Fidonet ready?' | ||
}]); | ||
url = FGHIURL( | ||
'netmail:2:5030/830.17?subject=Yet+another+GoldEd%2b+feature' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '830'); | ||
assert.equal(url.stationPoint, '17'); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'subject', | ||
value: 'Yet another GoldEd+ feature' | ||
}]); | ||
url = FGHIURL( | ||
'netmail:2:5030/84?to=R50EC&subject=%D0%AD%D1%85%D0%B8' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '84'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'to', | ||
value: 'R50EC' | ||
}, { | ||
name: 'subject', | ||
value: 'Эхи' | ||
}]); | ||
}); | ||
it('section 6.1.3', function(){ | ||
var url = FGHIURL( | ||
'netmail:2:5030/84?to=R50EC&from=Moderator&subject=New+echo+rules' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '84'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'to', | ||
value: 'R50EC' | ||
}, { | ||
name: 'from', | ||
value: 'Moderator' | ||
}, { | ||
name: 'subject', | ||
value: 'New echo rules' | ||
}]); | ||
url = FGHIURL( | ||
'netmail:2:5024/1024?from=Moderator&subject=%5B%21%5D+read+only' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5024'); | ||
assert.equal(url.stationNode, '1024'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'from', | ||
value: 'Moderator' | ||
}, { | ||
name: 'subject', | ||
value: '[!] read only' | ||
}]); | ||
}); | ||
it('section 6.1.4', function(){ | ||
var url = FGHIURL( | ||
'netmail:2:5063/88?subject=About+FGHI&body=Fidonet+2.0+draft' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5063'); | ||
assert.equal(url.stationNode, '88'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'subject', | ||
value: 'About FGHI' | ||
}, { | ||
name: 'body', | ||
value: 'Fidonet 2.0 draft' | ||
}]); | ||
url = FGHIURL( | ||
'netmail:2:50/0?subject=Complaint&body=A+sysop+is+annoying' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '50'); | ||
assert.equal(url.stationNode, '0'); | ||
assert.equal(url.stationPoint, ''); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'subject', | ||
value: 'Complaint' | ||
}, { | ||
name: 'body', | ||
value: 'A sysop is annoying' | ||
}]); | ||
url = FGHIURL( | ||
'netmail:2:5030/1520.9?body=HellEd+needs+enormously+large+DLLs' | ||
); | ||
assert.equal(url.scheme, 'netmail'); | ||
assert.equal(url.stationZone, '2'); | ||
assert.equal(url.stationNet, '5030'); | ||
assert.equal(url.stationNode, '1520'); | ||
assert.equal(url.stationPoint, '9'); | ||
assert.equal(url.stationDomain, ''); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'body', | ||
value: 'HellEd needs enormously large DLLs' | ||
}]); | ||
}); | ||
}); | ||
describe("processes 'areafix:' examples (section 6.2)", function(){ | ||
it('section 6.2 initial part', function(){ | ||
var url = FGHIURL('areafix:SU.FidoTech'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [['SU.FidoTech']]); | ||
url = FGHIURL('areafix:Ru.Fidonet.Today'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [['Ru.Fidonet.Today']]); | ||
url = FGHIURL('areafix:Ru.FTN.Develop+Ru.FTN.WinSoft'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [ | ||
['Ru.FTN.Develop'], | ||
['Ru.FTN.WinSoft'] | ||
]); | ||
url = FGHIURL('areafix:Ru.Computer.Humor%20Ru.Hutor.Filtered'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [ | ||
['Ru.Computer.Humor'], | ||
['Ru.Hutor.Filtered'] | ||
]); | ||
url = FGHIURL('areafix:Titanic.Best+Titanic.Forward%20Titanic.PVT'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [ | ||
['Titanic.Best'], | ||
['Titanic.Forward'], | ||
['Titanic.PVT'] | ||
]); | ||
}); | ||
it('section 6.2.1', function(){ | ||
var url = FGHIURL('areafix:Ru.Embedded?uplink=2:5029/32'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [['Ru.Embedded']]); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'uplink', | ||
value: '2:5029/32' | ||
}]); | ||
url = FGHIURL('areafix:Titanic.PVT?uplink=2:5020/830'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [['Titanic.PVT']]); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'uplink', | ||
value: '2:5020/830' | ||
}]); | ||
}); | ||
it('section 6.2.2', function(){ | ||
var url = FGHIURL('areafix:Ru.PHP?leave'); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [['Ru.PHP']]); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'leave', | ||
value: '' | ||
}]); | ||
url = FGHIURL( | ||
'areafix:Ru.List.Citycat.Culture.Music.Announce.FantasyNews?leave' | ||
); | ||
assert.equal(url.scheme, 'areafix'); | ||
assert.deepEqual(url.echoNames, [[ | ||
'Ru.List.Citycat.Culture.Music.Announce.FantasyNews' | ||
]]); | ||
assert.deepEqual(url.optionalParams, [{ | ||
name: 'leave', | ||
value: '' | ||
}]); | ||
}); | ||
}); | ||
}); | ||
describe('Detection of filters', function(){ | ||
it('detects when a filter is given', function(){ | ||
assert( FGHIURL('area://Ru.FTN.Develop/?time=2014').hasFilters() ); | ||
assert( FGHIURL('area://Ru.FTN.Develop?ttop').hasFilters() ); | ||
assert( FGHIURL('area://Ru.FTN.Develop?ttop&view=mapm').hasFilters() ); | ||
}); | ||
it('detects when there are no filters', function(){ | ||
assert(! FGHIURL('areafix:Ru.FTN.Develop').hasFilters() ); | ||
assert(! FGHIURL('area://Ru.FTN.Develop').hasFilters() ); | ||
assert(! FGHIURL('area://Ru.FTN.Develop/').hasFilters() ); | ||
assert(! FGHIURL('area://Ru.FTN.Develop/ttop').hasFilters() ); | ||
assert(! FGHIURL('area://Ru.FTN.Develop?view=mapm').hasFilters() ); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
825819
773
91