@extractus/feed-extractor
Advanced tools
Comparing version 7.1.1 to 7.1.2
{ | ||
"version": "7.1.1", | ||
"version": "7.1.2", | ||
"name": "@extractus/feed-extractor", | ||
@@ -31,2 +31,12 @@ "description": "To read and normalize RSS/ATOM/JSON feed data", | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"build": "node build", | ||
"prepublishOnly": "npm run build", | ||
"pretest": "npm run lint", | ||
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true", | ||
"eval": "node eval", | ||
"reset": "node reset" | ||
}, | ||
"dependencies": { | ||
@@ -54,12 +64,3 @@ "bellajs": "^11.1.3", | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"lint:fix": "eslint --fix .", | ||
"build": "node build", | ||
"pretest": "npm run lint", | ||
"test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true", | ||
"eval": "node eval", | ||
"reset": "node reset" | ||
} | ||
} | ||
"license": "MIT" | ||
} |
// utils -> retrieve | ||
import fetch from 'cross-fetch' | ||
import { XMLParser } from 'fast-xml-parser' | ||
@@ -18,2 +19,16 @@ const profetch = async (url, options = {}) => { | ||
const getCharsetFromText = (text) => { | ||
try { | ||
const firstLine = text.split('\n')[0].trim().replace('<?', '<').replace('?>', '>') | ||
const parser = new XMLParser({ | ||
ignoreAttributes: false, | ||
}) | ||
let obj = parser.parse(firstLine) | ||
const { xml: root = {} } = obj | ||
return root['@_encoding'] || 'utf8' | ||
} catch { | ||
return 'utf8' | ||
} | ||
} | ||
export default async (url, options = {}) => { | ||
@@ -39,5 +54,6 @@ const { | ||
console.log(contentType) | ||
if (/(\+|\/)(xml|html)/.test(contentType)) { | ||
const arr = contentType.split('charset=') | ||
const charset = arr.length === 2 ? arr[1].trim() : 'utf8' | ||
let charset = arr.length === 2 ? arr[1].trim() : getCharsetFromText(text) | ||
const decoder = new TextDecoder(charset) | ||
@@ -44,0 +60,0 @@ const xml = decoder.decode(buffer) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121891
1795