Skip to content

Commit e60e72e

Browse files
authored
Merge pull request #128 from extractus/7.1.1
v7.1.1
2 parents 38a50fe + 0bd1f4b commit e60e72e

File tree

8 files changed

+145
-135
lines changed

8 files changed

+145
-135
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 121 deletions
This file was deleted.

.github/workflows/ci-test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node_version: [18.x, 20.x, 21.x]
15+
node_version: [18.x, 20.x, 22.x]
1616

1717
steps:
1818
- uses: actions/checkout@v4
@@ -27,8 +27,6 @@ jobs:
2727
PROXY_SERVER: ${{ secrets.PROXY_SERVER }}
2828
run: |
2929
npm install
30-
npm run lint
31-
npm run build --if-present
3230
npm run test
3331
3432
- name: Coveralls Parallel

eslint.config.js

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// eslint.config.js
2+
3+
import eslintjs from '@eslint/js'
4+
import globals from 'globals'
5+
6+
export default [
7+
eslintjs.configs.recommended,
8+
{
9+
languageOptions: {
10+
ecmaVersion: 'latest',
11+
sourceType: 'module',
12+
globals: {
13+
...globals.node,
14+
...globals.browser,
15+
...globals.jest,
16+
Intl: 'readonly',
17+
},
18+
},
19+
ignores: [
20+
'node_modules',
21+
'storage',
22+
'*.cjs',
23+
],
24+
rules: {
25+
'arrow-spacing': ['error', { 'before': true, 'after': true }],
26+
'block-spacing': ['error', 'always'],
27+
'brace-style': ['error', '1tbs', { 'allowSingleLine': true }],
28+
'camelcase': ['error', {
29+
'allow': ['^UNSAFE_'],
30+
'properties': 'never',
31+
'ignoreGlobals': true,
32+
}],
33+
'comma-dangle': ['error', {
34+
'arrays': 'always-multiline',
35+
'objects': 'always-multiline',
36+
'imports': 'never',
37+
'exports': 'never',
38+
'functions': 'never',
39+
}],
40+
'comma-spacing': ['error', { 'before': false, 'after': true }],
41+
'eol-last': 'error',
42+
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
43+
'func-call-spacing': ['error', 'never'],
44+
'indent': [
45+
'error',
46+
2,
47+
{
48+
'MemberExpression': 1,
49+
'FunctionDeclaration': {
50+
'body': 1,
51+
'parameters': 2,
52+
},
53+
'SwitchCase': 1,
54+
'ignoredNodes': ['TemplateLiteral > *'],
55+
},
56+
],
57+
'key-spacing': ['error', { 'beforeColon': false, 'afterColon': true }],
58+
'keyword-spacing': ['error', { 'before': true, 'after': true }],
59+
'lines-between-class-members': ['error', 'always', { 'exceptAfterSingleLine': true }],
60+
'max-len': [
61+
'error',
62+
{
63+
'code': 120,
64+
'ignoreTrailingComments': true,
65+
'ignoreComments': true,
66+
'ignoreUrls': true,
67+
},
68+
],
69+
'max-lines': [
70+
'error',
71+
{
72+
'max': 500,
73+
'skipBlankLines': true,
74+
'skipComments': false,
75+
},
76+
],
77+
'max-lines-per-function': [
78+
'error',
79+
{
80+
'max': 200,
81+
'skipBlankLines': true,
82+
},
83+
],
84+
'max-params': ['error', 3],
85+
'no-array-constructor': 'error',
86+
'no-mixed-spaces-and-tabs': 'error',
87+
'no-multi-spaces': 'error',
88+
'no-multi-str': 'error',
89+
'no-multiple-empty-lines': [
90+
'error',
91+
{
92+
'max': 1,
93+
'maxEOF': 0,
94+
},
95+
],
96+
'no-restricted-syntax': [
97+
'error',
98+
'WithStatement',
99+
'BinaryExpression[operator=\'in\']',
100+
],
101+
'no-trailing-spaces': 'error',
102+
'no-use-before-define': [
103+
'error',
104+
{
105+
'functions': true,
106+
'classes': true,
107+
'variables': false,
108+
},
109+
],
110+
'no-var': 'warn',
111+
'object-curly-spacing': ['error', 'always'],
112+
'padded-blocks': [
113+
'error',
114+
{
115+
'blocks': 'never',
116+
'switches': 'never',
117+
'classes': 'never',
118+
},
119+
],
120+
'quotes': ['error', 'single'],
121+
'space-before-blocks': ['error', 'always'],
122+
'space-before-function-paren': ['error', 'always'],
123+
'space-infix-ops': 'error',
124+
'space-unary-ops': ['error', { 'words': true, 'nonwords': false }],
125+
'space-in-parens': ['error', 'never'],
126+
'semi': ['error', 'never'],
127+
},
128+
},
129+
]

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "7.1.0",
2+
"version": "7.1.1",
33
"name": "@extractus/feed-extractor",
44
"description": "To read and normalize RSS/ATOM/JSON feed data",
55
"homepage": "https://extractor-demos.pages.dev",
@@ -46,7 +46,8 @@
4646
},
4747
"devDependencies": {
4848
"esbuild": "^0.20.2",
49-
"eslint": "^8.57.0",
49+
"eslint": "^9.1.1",
50+
"globals": "^15.0.0",
5051
"https-proxy-agent": "^7.0.4",
5152
"jest": "^29.7.0",
5253
"nock": "^13.5.4"

src/utils/linker.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const isValid = (url = '') => {
44
try {
55
const ourl = new URL(url)
66
return ourl !== null && ourl.protocol.startsWith('http')
7-
} catch (err) {
7+
} catch {
88
return false
99
}
1010
}
@@ -13,7 +13,7 @@ export const absolutify = (fullUrl = '', relativeUrl = '') => {
1313
try {
1414
const result = new URL(relativeUrl, fullUrl)
1515
return result.toString()
16-
} catch (err) {
16+
} catch {
1717
return ''
1818
}
1919
}
@@ -87,7 +87,7 @@ export const purify = (url) => {
8787
})
8888

8989
return pureUrl.toString().replace(pureUrl.hash, '')
90-
} catch (err) {
90+
} catch {
9191
return null
9292
}
9393
}

src/utils/normalizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { absolutify, isValid as isValidUrl, purify as purifyUrl } from './linker
1616
export const toISODateString = (dstr) => {
1717
try {
1818
return dstr ? (new Date(dstr)).toISOString() : ''
19-
} catch (err) {
19+
} catch {
2020
return ''
2121
}
2222
}

src/utils/retrieve.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ export default async (url, options = {}) => {
3232
throw new Error(`Request failed with error code ${status}`)
3333
}
3434
const contentType = res.headers.get('content-type')
35-
const text = await res.text()
35+
const buffer = await res.arrayBuffer()
36+
const text = buffer ? Buffer.from(buffer).toString().trim() : ''
3637

3738
if (/(\+|\/)(xml|html)/.test(contentType)) {
38-
return { type: 'xml', text: text.trim(), status, contentType }
39+
const arr = contentType.split('charset=')
40+
const charset = arr.length === 2 ? arr[1].trim() : 'utf8'
41+
const decoder = new TextDecoder(charset)
42+
const xml = decoder.decode(buffer)
43+
return { type: 'xml', text: xml.trim(), status, contentType }
3944
}
4045

4146
if (/(\+|\/)json/.test(contentType)) {
4247
try {
4348
const data = JSON.parse(text)
4449
return { type: 'json', json: data, status, contentType }
45-
} catch (err) {
50+
} catch {
4651
throw new Error('Failed to convert data to JSON object')
4752
}
4853
}

0 commit comments

Comments
 (0)