You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(`Feed data from ${url} has been parsed successfully`)
104
-
console.log('`feed` is always an object that contains feed data')
105
-
console.log(feed)
106
-
})
107
-
108
-
onError((url, err) => {
109
-
console.log(`Error occurred while processing ${url}`)
110
-
console.log('There is a message and reason:')
111
-
console.log(err)
112
-
})
113
-
114
-
onComplete((url, result, error) => {
115
-
console.log(`Finish processing ${url}`)
116
-
console.log('`result` may be feed data or null')
117
-
console.log(result)
118
-
console.log('`error` may be an error object or null')
119
-
if (error) {
120
-
console.log(error.message)
121
-
console.log(error.reason)
122
-
}
123
-
})
124
-
125
-
read('https://news.google.com/rss')
126
-
read('https://google.com')
127
-
```
128
-
129
-
We can mix both style together, for example to handle the error:
130
-
131
-
```js
132
-
import { read, onError } from'feed-reader'
133
-
134
-
onError((url, err) => {
135
-
console.log(`Error occurred while processing ${url}`)
136
-
console.log('There is a message and reason:')
137
-
console.log(err)
138
-
})
139
-
140
-
constgetFeedData=async (url) => {
141
-
constresult=awaitread(url)
142
-
// `result` may be feed data or null
143
-
return result
144
-
}
145
-
146
-
getFeedData('https://news.google.com/rss')
147
-
````
148
-
149
-
In almost cases, using just `onComplete` is enough:
150
-
151
-
```js
152
-
import { read, onComplete } from 'feed-reader'
153
-
154
-
onComplete((url, result, error) => {
155
-
console.log(`Finish processing ${url}`)
156
-
if (result) {
157
-
// save feed data
158
-
console.log(result)
159
-
}
160
-
if (error) {
161
-
// handle error info
162
-
console.log(error)
163
-
}
164
-
})
165
-
166
-
read('https://news.google.com/rss')
167
-
````
168
-
169
-
#### Reset event listeners
170
-
171
-
Use method `resetEvents()` when you want to clear registered listeners from all events.
172
-
173
-
```js
174
-
import { resetEvents } from'feed-reader'
175
-
176
-
resetEvents()
177
-
````
178
-
179
88
### Configuration methods
180
89
181
90
#### `setRequestOptions(Object requestOptions)`
@@ -188,6 +97,18 @@ Return current request options.
188
97
189
98
Default values can be found [here](https://github.com/ndaidong/feed-reader/blob/main/src/config.js#L5).
190
99
100
+
#### `setReaderOptions(Object readerOptions)`
101
+
102
+
To change default reader options.
103
+
104
+
-`descriptionMaxLen`: Number, max num of chars for description (default: `210`)
105
+
-`includeFullContent`: Boolean, add `content` to entry if available (default: `false`)
106
+
-`convertPubDateToISO`: Boolean, reformat published date to [ISO standard](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) (default: `true`)
0 commit comments