canada-api 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/index.mjs +12 -14
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Cross platform API for fetching public data from [canada.ca](https://www.canada.
|
|
|
5
5
|
## Install
|
|
6
6
|
### Browsers
|
|
7
7
|
|
|
8
|
-
<script src="https://cdn.jsdelivr.net/npm/canada-api@1.0.
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/canada-api@1.0.3"><script>
|
|
9
9
|
|
|
10
10
|
### Nodejs
|
|
11
11
|
|
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const months = {
|
|
|
28
28
|
*/
|
|
29
29
|
function parseDate(date) {
|
|
30
30
|
let m = /^\w{3} (\w{3}) (\d{2}) (\d{4}) ([\d:]{8}) GMT([\-+]\d{4})$/.exec(date)
|
|
31
|
-
return m ?
|
|
31
|
+
return m ? Date.parse(m[3] + '-' + months[m[1]] + '-' + m[2] + 'T' + m[4] + m[5]) : date
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -116,7 +116,7 @@ function verifyResponse(response) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Get node children
|
|
119
|
+
* Get node children by parsing sitemaps
|
|
120
120
|
* @param {string|Object} node
|
|
121
121
|
* @param {array} list Node list to extend
|
|
122
122
|
* @returns {Object}
|
|
@@ -127,18 +127,15 @@ export function children(node) {
|
|
|
127
127
|
return limiter.schedule(() => fetch(formatURL(node.path, '.sitemap.xml')))
|
|
128
128
|
.then(verifyResponse)
|
|
129
129
|
.then(response => response.text())
|
|
130
|
-
.then(xml => {
|
|
131
|
-
|
|
132
|
-
let
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.catch(err => {
|
|
140
|
-
return err
|
|
141
|
-
})
|
|
130
|
+
.then(xml => xml.match(/<url>.*?<\/url>/g).map(url => {
|
|
131
|
+
let loc = url.match(/<loc>([^<]+)<\/loc>/)
|
|
132
|
+
let mod = url.match(/<lastmod>([^<]+)<\/lastmod>/)
|
|
133
|
+
return {
|
|
134
|
+
path: normalizePath(loc[1]),
|
|
135
|
+
lastmod: mod ? Date.parse(mod[1]) : null
|
|
136
|
+
}
|
|
137
|
+
}))
|
|
138
|
+
.catch(() => [])
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
/**
|
|
@@ -201,3 +198,4 @@ export function content(node) {
|
|
|
201
198
|
return node
|
|
202
199
|
})
|
|
203
200
|
}
|
|
201
|
+
|