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

sitemap2

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sitemap2 - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

test/data/video.xml

30

dist/errors.js

@@ -7,6 +7,8 @@ 'use strict';

var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x5,
property = _x6,
receiver = _x7; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
var _get = function get(_x6, _x7, _x8) { var _again = true; _function: while (_again) { desc = parent = getter = undefined; _again = false; var object = _x6,
property = _x7,
receiver = _x8; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x6 = parent; _x7 = property; _x8 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

@@ -16,2 +18,6 @@

var _utils = require('./utils');
var _utils2 = _interopRequireDefault(_utils);
var NoURLError = (function (_Error) {

@@ -79,2 +85,18 @@ function NoURLError() {

exports.PriorityInvalidError = PriorityInvalidError;
exports.PriorityInvalidError = PriorityInvalidError;
var VideoNoRequiredFieldsError = (function (_Error5) {
function VideoNoRequiredFieldsError() {
var message = arguments[0] === undefined ? 'fields [' + _utils2['default'].join(', ') + '] are required' : arguments[0];
_classCallCheck(this, VideoNoRequiredFieldsError);
_get(Object.getPrototypeOf(VideoNoRequiredFieldsError.prototype), 'constructor', this).call(this, message, 'VideoNoRequiredFieldsError');
}
_inherits(VideoNoRequiredFieldsError, _Error5);
return VideoNoRequiredFieldsError;
})(Error);
exports.VideoNoRequiredFieldsError = VideoNoRequiredFieldsError;

@@ -104,2 +104,5 @@ 'use strict';

}
if (urlData.video) {
data.video = _utils.validateVideo(urlData.video);
}

@@ -174,2 +177,3 @@ this.urls.push(data);

urlset.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
urls.forEach(function (url) {

@@ -183,2 +187,11 @@ var urlEl = urlset.ele('url');

}
if (url.video) {
(function () {
urlset.att('xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1');
var video = urlEl.ele('video:video');
Object.keys(url.video).forEach(function (key) {
video.ele('video:' + key, {}, url.video[key]);
});
})();
}
});

@@ -185,0 +198,0 @@

@@ -21,2 +21,3 @@ 'use strict';

exports.validateLastMod = validateLastMod;
exports.validateVideo = validateVideo;

@@ -87,2 +88,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

return [dt.getFullYear(), lpad(dt.getMonth() + 1, 2), lpad(dt.getDate(), 2)].join('-');
}
var VIDEO_REQUIRED_FIELDS = ['title', 'description', 'thumbnail_loc', 'content_loc'];
exports.VIDEO_REQUIRED_FIELDS = VIDEO_REQUIRED_FIELDS;
function validateVideo(videoTag) {
var requiredFieldsExist = VIDEO_REQUIRED_FIELDS.every(function (e) {
return videoTag[e];
});
if (!requiredFieldsExist) {
throw new _errors.VideoNoRequiredFieldsError();
}
return videoTag;
}

@@ -0,1 +1,3 @@

import VIDEO_REQUIRED_FIELDS from './utils';
export class NoURLError extends Error {

@@ -24,1 +26,7 @@ constructor(message = 'URL is required') {

}
export class VideoNoRequiredFieldsError extends Error {
constructor(message = `fields [${VIDEO_REQUIRED_FIELDS.join(', ')}] are required`) {
super(message, 'VideoNoRequiredFieldsError');
}
}

@@ -7,3 +7,4 @@ import xmlbuilder from 'xmlbuilder';

validatePriority,
validateLastMod
validateLastMod,
validateVideo
} from './utils';

@@ -64,3 +65,2 @@

let data = {

@@ -75,2 +75,5 @@ url: validateURL(urlData.url),

}
if (urlData.video) {
data.video = validateVideo(urlData.video);
}

@@ -141,2 +144,3 @@ this.urls.push(data);

urlset.att('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
urls.forEach(url => {

@@ -150,2 +154,9 @@ let urlEl = urlset.ele('url');

}
if (url.video) {
urlset.att('xmlns:video', 'http://www.google.com/schemas/sitemap-video/1.1');
let video = urlEl.ele('video:video');
Object.keys(url.video).forEach(key => {
video.ele(`video:${key}`, {}, url.video[key]);
});
}
});

@@ -152,0 +163,0 @@

@@ -6,3 +6,4 @@ import urlParser from 'url';

ChangeFreqInvalidError,
PriorityInvalidError
PriorityInvalidError,
VideoNoRequiredFieldsError
} from './errors';

@@ -79,1 +80,13 @@

}
export const VIDEO_REQUIRED_FIELDS = ['title', 'description', 'thumbnail_loc', 'content_loc'];
export function validateVideo(videoTag) {
let requiredFieldsExist = VIDEO_REQUIRED_FIELDS.every(e => videoTag[e]);
if (!requiredFieldsExist) {
throw new VideoNoRequiredFieldsError();
}
return videoTag;
}

2

package.json
{
"name": "sitemap2",
"version": "0.1.1",
"version": "0.2.0",
"description": "Sitemap-generating framework",

@@ -5,0 +5,0 @@ "keywords": [

@@ -20,3 +20,3 @@ [![Build Status](https://travis-ci.org/vlkosinov/sitemap2.svg?branch=master)](https://travis-ci.org/vlkosinov/sitemap2)

var fs = require('fs');
var Sitemap = require('./dist');
var Sitemap = require('sitemap2');

@@ -23,0 +23,0 @@ var host = 'http://vk.com';

@@ -94,2 +94,21 @@ var readDir = require('fs-readdir-recursive'),

describe('video arg', function () {
it('should video tag', function () {
var sm = new Sitemap();
sm.addUrl({
url: 'http://test.com',
video: {
title: 'Grilling steaks for summer',
description: 'Alkis shows you how to get perfectly done steaks every time',
thumbnail_loc: 'http://www.example.com/thumbs/123.jpg',
content_loc: 'http://www.example.com/video123.flv'
}
});
var result = sm.toXML()[0].xml;
result.should.equal(dataExpected['video.xml']);
});
});
describe('invalid arguments', function () {

@@ -136,2 +155,22 @@

it('should throw VideoNoRequiredFieldsError', function () {
var fn = sitemap.addUrl.bind(sitemap, {url: 'http://test.com', video: {}});
expect(fn).to.throw(errors.VideoNoRequiredFieldsError);
fn = sitemap.addUrl.bind(sitemap, {url: 'http://test.com', video: {title: 'lalala'}});
expect(fn).to.throw(errors.VideoNoRequiredFieldsError);
fn = sitemap.addUrl.bind(sitemap, {
url: 'http://test.com',
video: {
title: 'Grilling steaks for summer',
description: 'Alkis shows you how to get perfectly done steaks every time',
thumbnail_loc: 'http://www.example.com/thumbs/123.jpg',
content_loc: 'http://www.example.com/video123.flv'
}
});
expect(fn).not.to.throw(errors.VideoNoRequiredFieldsError);
});
});

@@ -138,0 +177,0 @@

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