Skip to content
Permalink
Browse files

Updates Node. Updates dependencies. Refactoring

  • Loading branch information...
zrrrzzt committed Jun 9, 2017
1 parent cac5080 commit 6646fac06b03a15ef37feeb62b75f284976029e3
Showing with 66 additions and 65 deletions.
  1. +1 −3 .travis.yml
  2. +33 −25 README.md
  3. +13 −13 index.js
  4. +6 −6 lib/convertSitemapData.js
  5. +1 −3 lib/objectFromArray.js
  6. +12 −12 package.json
  7. +0 −3 setup.js
@@ -1,7 +1,5 @@
language: node_js
node_js:
- "4.1"
- "0.12"
- "iojs"
- "4"
after_success:
- npm run coveralls
@@ -1,7 +1,9 @@
[![Build Status](https://travis-ci.org/zrrrzzt/sitemap-to-array.svg?branch=master)](https://travis-ci.org/zrrrzzt/sitemap-to-array)
[![Coverage Status](https://coveralls.io/repos/zrrrzzt/sitemap-to-array/badge.svg?branch=master&service=github)](https://coveralls.io/github/zrrrzzt/sitemap-to-array?branch=master)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

# sitemap-to-array

Convert a sitemap.xml to an array or stream of objects.

## Installation
@@ -32,15 +34,15 @@ Pass a sitemap, either as data or an URL to the sitemap.xml.
```javascript
'use strict'
var fs = require('fs')
var smta = require('sitemap-to-array')
var data = fs.readFileSync('test/data/sitemap.xml', 'utf-8')
const fs = require('fs')
const smta = require('sitemap-to-array')
const data = fs.readFileSync('test/data/sitemap.xml', 'utf-8')
smta(data, function (stream) {
stream.on('error', function (error) {
smta(data, stream => {
stream.on('error', error => {
console.error(error)
})
stream.on('data', function (data) {
stream.on('data', data => {
console.log(data.toString())
})
})
@@ -61,14 +63,14 @@ Returns
```javascript
'use strict'
var smta = require('sitemap-to-array')
var sitemapUrl = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
const smta = require('sitemap-to-array')
const sitemapUrl = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
smta(sitemapUrl, function (stream) {
stream.on('error', function (error) {
smta(sitemapUrl, stream => {
stream.on('error', error => {
console.error(error)
})
stream.on('data', function (data) {
stream.on('data', data => {
console.log(data.toString())
})
})
@@ -87,13 +89,13 @@ Returns

```javascript
'use strict'
var smta = require('sitemap-to-array')
var options = {
const smta = require('sitemap-to-array')
const options = {
returnOnComplete: true
}
var sitemapUrl = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
const sitemapUrl = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
smta(sitemapUrl, options, function (error, list) {
smta(sitemapUrl, options, (error, list) => {
if (error) {
console.error(error)
} else {
@@ -128,15 +130,15 @@ pipe a stream of sitemap.xml to the module
```javascript
'use strict'
var smtaStream = require('sitemap-to-array').stream
var http = require('http')
var sitemap = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
const smtaStream = require('sitemap-to-array').stream
const http = require('http')
const sitemap = 'https://raw.githubusercontent.com/zrrrzzt/sitemap-to-array/master/test/data/sitemap.xml'
smtaStream.on('data', function (data) {
smtaStream.on('data', data => {
console.log(data.toString())
})
http.get(sitemap, function (response) {
http.get(sitemap, response => {
response
.pipe(smtaStream)
})
@@ -158,11 +160,11 @@ returns
```javascript
'use strict'
var smtaStream = require('sitemap-to-array').stream
var fs = require('fs')
var sitemap = fs.createReadStream('test/data/sitemap.xml')
const smtaStream = require('sitemap-to-array').stream
const fs = require('fs')
const sitemap = fs.createReadStream('test/data/sitemap.xml')
smtaStream.on('data', function (data) {
smtaStream.on('data', data => {
console.log(data.toString())
})
@@ -179,4 +181,10 @@ returns
{"loc":"http://www.telemark.no/Vaare-tjenester/Folkehelse","lastmod":"2015-03-13T07:35:30+00:00"}
{"loc":"http://www.telemark.no/Vaare-tjenester/Folkehelse/Tilbud-HEFRES/Paa-farta-til-skolen","lastmod":"2015-05-24T15:56:56+00:00"}
{"loc":"http://www.telemark.no/Vaare-tjenester/Folkehelse/Tilbud-HEFRES/Alle-barn-sykler","lastmod":"2015-05-22T13:46:26+00:00"}
```
```

## License

[MIT](LICENSE)

![Robohash image of sitemap-to-array](https://robots.kebabstudios.party/sitemap-to-array.png "Robohash image of sitemap-to-array")
@@ -1,10 +1,10 @@
'use strict'

var validUrl = require('valid-url')
var hh = require('http-https')
var streamifier = require('streamifier')
var streamify = require('streamify')
var convertStream = require('./lib/convertSitemapData')
const validUrl = require('valid-url')
const hh = require('http-https')
const streamifier = require('streamifier')
const streamify = require('streamify')
const convertStream = require('./lib/convertSitemapData')

function sitemapToArray (sitemap, options, callback) {
if (!sitemap) {
@@ -16,33 +16,33 @@ function sitemapToArray (sitemap, options, callback) {
options = {}
}

var returnOnComplete = options.returnOnComplete || false
var list = returnOnComplete ? [] : require('stream').PassThrough()
var stream = false
var err = null
const returnOnComplete = options.returnOnComplete || false
const list = returnOnComplete ? [] : require('stream').PassThrough()
let stream = false
let err = null

if (validUrl.isWebUri(sitemap)) {
stream = streamify()
hh.get(sitemap, function (response) {
hh.get(sitemap, response => {
stream.resolve(response)
})
} else {
stream = streamifier.createReadStream(sitemap)
}

convertStream.on('data', function (data) {
convertStream.on('data', data => {
list.push(returnOnComplete ? JSON.parse(data.toString()) : data)
})

convertStream.on('end', function () {
convertStream.on('end', () => {
if (returnOnComplete) {
return callback(err, list)
} else {
list.push(null)
}
})

convertStream.on('error', function (error) {
convertStream.on('error', error => {
err = error
if (!returnOnComplete) {
list.emit('error', error)
@@ -1,14 +1,14 @@
'use strict'

var duplexify = require('duplexify')
var saxStream = require('sax').createStream(true, {trim: true})
var readStream = require('stream').PassThrough()
var objectFromArray = require('./objectFromArray')
var list = []
const duplexify = require('duplexify')
const saxStream = require('sax').createStream(true, {trim: true})
const readStream = require('stream').PassThrough()
const objectFromArray = require('./objectFromArray')
let list = []

saxStream.on('opentag', function (node) {
if (node.name !== 'urlset' && node.name !== 'sitemapindex') {
if (node.name === 'url' && list.length > 0 || node.name === 'sitemap' && list.length > 0) {
if ((node.name === 'url' && list.length > 0) || (node.name === 'sitemap' && list.length > 0)) {
readStream.push(JSON.stringify(objectFromArray(list)))
list = []
} else {
@@ -1,6 +1,6 @@
'use strict'

function objectFromArray (arr) {
module.exports = arr => {
if (!arr) {
throw new Error('No input. Input must be an array')
}
@@ -13,5 +13,3 @@ function objectFromArray (arr) {
}
return obj
}

module.exports = objectFromArray
@@ -1,7 +1,7 @@
{
"name": "sitemap-to-array",
"description": "Convert sitemap.xml to an array or stream of objects",
"version": "4.0.0",
"version": "5.0.0",
"license": "MIT",
"author": {
"name": "Geir Gåsodden",
@@ -23,26 +23,26 @@
"url": "http://github.com/zrrrzzt/sitemap-to-array/issues"
},
"engines": {
"node": ">=0.12.0"
"node": ">=4.8.3"
},
"main": "index.js",
"scripts": {
"test": "standard && tap --reporter=spec test/*.js",
"coverage": "tap test/*.js --coverage",
"coveralls": "tap --cov --coverage-report=lcov test/*.js && cat coverage/lcov.info | coveralls",
"setup": "npm install && node setup.js"
"setup": "npm install"
},
"dependencies": {
"duplexify": "^3.4.2",
"http-https": "^1.0.0",
"sax": "^1.1.4",
"streamifier": "^0.1.1",
"streamify": "^0.2.5",
"valid-url": "^1.0.9"
"duplexify": "3.5.0",
"http-https": "1.0.0",
"sax": "1.2.2",
"streamifier": "0.1.1",
"streamify": "0.2.8",
"valid-url": "1.0.9"
},
"devDependencies": {
"coveralls": "^2.11.6",
"standard": "^10.0.1",
"tap": "^10.1.0"
"coveralls": "2.13.1",
"standard": "10.0.2",
"tap": "10.3.3"
}
}

This file was deleted.

0 comments on commit 6646fac

Please sign in to comment.
You can’t perform that action at this time.