Socket
Socket
Sign inDemoInstall

sitemap

Package Overview
Dependencies
Maintainers
0
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemap - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

33

lib/errors.js

@@ -7,13 +7,10 @@ /*!

exports.NoURLError = NoURLError;
exports.NoURLProtocolError = NoURLProtocolError;
/**
* URL in SitemapItem does not exists
*/
function NoURLError (message) {
exports.NoURLError = function (message) {
this.name = 'NoURLError';
this.message = message || '';
this.message = message || 'URL is required';
}
NoURLError.prototype = Error.prototype;
exports.NoURLError.prototype = Error.prototype;

@@ -23,6 +20,24 @@ /**

*/
function NoURLProtocolError (message) {
exports.NoURLProtocolError = function (message) {
this.name = 'NoURLProtocolError';
this.message = message || '';
this.message = message || 'Protocol is required';
}
NoURLProtocolError.prototype = Error.prototype;
exports.NoURLProtocolError.prototype = Error.prototype;
/**
* changefreq property in sitemap is invalid
*/
exports.ChangeFreqInvalidError = function (message) {
this.name = 'ChangeFreqInvalidError';
this.message = message || 'changefreq is invalid';
}
exports.ChangeFreqInvalidError.prototype = Error.prototype;
/**
* priority property in sitemap is invalid
*/
exports.PriorityInvalidError = function (message) {
this.name = 'PriorityInvalidError';
this.message = message || 'priority is invalid';
}
exports.PriorityInvalidError.prototype = Error.prototype;

@@ -31,6 +31,7 @@ /*!

function SitemapItem(conf) {
var conf = conf || {};
var conf = conf || {}
, is_safe_url = conf['safe'];
if ( !conf['url'] ) {
throw new err.NoURLError('URL is required');
throw new err.NoURLError();
}

@@ -40,6 +41,6 @@

this.loc = conf['url'];
if ( ! conf['safe'] ) {
if ( !is_safe_url ) {
var url_parts = urlparser.parse(conf['url']);
if ( !url_parts['protocol'] ) {
throw new err.NoURLProtocolError('Protocol is required')
throw new err.NoURLProtocolError();
}

@@ -57,10 +58,18 @@

// TODO: check valid value
// How frequently the page is likely to change
this.changefreq = conf['changefreq'] || 'weekly';
if ( !is_safe_url ) {
if ( [ 'always', 'hourly', 'daily', 'weekly', 'monthly',
'yearly', 'never' ].indexOf(this.changefreq) === -1 ) {
throw new err.ChangeFreqInvalidError();
}
}
// TODO: check period
// The priority of this URL relative to other URLs
this.priority = conf['priority'] || 0.5;
if ( !is_safe_url ) {
if ( !(this.priority >= 0.0 && this.priority <= 1.0) ) {
throw new err.PriorityInvalidError();
}
}
}

@@ -67,0 +76,0 @@

{
"name": "sitemap",
"version": "0.3.0",
"version": "0.4.0",
"description": "Sitemap-generating framework",

@@ -5,0 +5,0 @@ "keywords": ["sitemap", "sitemap.xml"],

@@ -23,6 +23,4 @@ /*!

'sitemap item: error for url absence': function () {
var url = 'http://ya.ru'
, smi;
assert.throws(
function() { smi = new sm.SitemapItem(); },
function() { new sm.SitemapItem(); },
/URL is required/

@@ -102,6 +100,6 @@ );

urls: [
{ 'url': '/', 'changefreq': 'always', 'priority': 1 },
{ 'url': '/page-1/', 'changefreq': 'weekly', 'priority': 0.3 },
{ 'url': '/page-2/', 'changefreq': 'dayly', 'priority': 0.7 },
{ 'url': 'http://www.test.com/page-3/', 'changefreq': 'monthly', 'priority': 0.2 },
{ url: '/', changefreq: 'always', priority: 1 },
{ url: '/page-1/', changefreq: 'weekly', priority: 0.3 },
{ url: '/page-2/', changefreq: 'daily', priority: 0.7 },
{ url: 'http://www.test.com/page-3/', changefreq: 'monthly', priority: 0.2 },
]

@@ -125,3 +123,3 @@ });

'<loc>http://test.com/page-2/</loc> '+
'<changefreq>dayly</changefreq> '+
'<changefreq>daily</changefreq> '+
'<priority>0.7</priority> '+

@@ -136,2 +134,24 @@ '</url>\n'+

},
'sitemap: invalid changefreq error': function() {
assert.throws(
function() {
sm.createSitemap({
hostname: 'http://test.com',
urls: [{ url: '/', changefreq: 'allllways'}]
}).toXML();
},
/changefreq is invalid/
);
},
'sitemap: invalid priority error': function() {
assert.throws(
function() {
sm.createSitemap({
hostname: 'http://test.com',
urls: [{ url: '/', priority: 1.1}]
}).toXML();
},
/priority is invalid/
);
},
}
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