MCPcopy
hub / github.com/posthtml/posthtml / next

Method next

lib/index.js:187–235  ·  view source on GitHub ↗
(result, cb)

Source from the content-addressed store, hash-verified

185 let i = 0
186
187 const next = (result, cb) => {
188 _treeExtendApi(result, this)
189
190 // all plugins called
191 if (this.plugins.length <= i) {
192 cb(null, result)
193 return
194 }
195
196 // little helper to go to the next iteration
197 function _next (res) {
198 if (res && !options.skipParse) {
199 res = [].concat(res)
200 }
201
202 return next(res || result, cb)
203 }
204
205 // call next
206 const plugin = this.plugins[i++]
207
208 if (plugin.length === 2) {
209 plugin(result, (err, res) => {
210 if (err) return cb(err)
211 _next(res)
212 })
213 return
214 }
215
216 // sync and promised plugins
217 let err = null
218
219 const res = tryCatch(() => plugin(result), e => {
220 err = e
221 return e
222 })
223
224 if (err) {
225 cb(err)
226 return
227 }
228
229 if (isPromise(res)) {
230 res.then(_next).catch(cb)
231 return
232 }
233
234 _next(res)
235 }
236
237 return new Promise((resolve, reject) => {
238 next(tree, (err, tree) => {

Callers

nothing calls this directly

Calls 4

_treeExtendApiFunction · 0.85
tryCatchFunction · 0.85
isPromiseFunction · 0.85
pluginFunction · 0.50

Tested by

no test coverage detected