1- 'use strict'
2-
3- var bail = require ( 'bail' )
4- var buffer = require ( 'is-buffer' )
5- var extend = require ( 'extend' )
6- var plain = require ( 'is-plain-obj' )
7- var trough = require ( 'trough' )
8- var vfile = require ( 'vfile' )
1+ import { bail } from 'bail'
2+ import isBuffer from 'is-buffer'
3+ import extend from 'extend'
4+ import isPlainObj from 'is-plain-obj'
5+ import { trough } from 'trough'
6+ import { VFile } from 'vfile'
97
108// Expose a frozen processor.
11- module . exports = unified ( ) . freeze ( )
9+ export const unified = base ( ) . freeze ( )
1210
1311var slice = [ ] . slice
1412var own = { } . hasOwnProperty
@@ -42,15 +40,15 @@ function pipelineStringify(p, ctx) {
4240
4341 if ( result === undefined || result === null ) {
4442 // Empty.
45- } else if ( typeof result === 'string' || buffer ( result ) ) {
46- ctx . file . contents = result
43+ } else if ( typeof result === 'string' || isBuffer ( result ) ) {
44+ ctx . file . value = result
4745 } else {
4846 ctx . file . result = result
4947 }
5048}
5149
5250// Function to create the first processor.
53- function unified ( ) {
51+ function base ( ) {
5452 var attachers = [ ]
5553 var transformers = trough ( )
5654 var namespace = { }
@@ -80,7 +78,7 @@ function unified() {
8078
8179 // Create a new processor based on the processor in the current scope.
8280 function processor ( ) {
83- var destination = unified ( )
81+ var destination = base ( )
8482 var index = - 1
8583
8684 while ( ++ index < attachers . length ) {
@@ -172,7 +170,7 @@ function unified() {
172170 if ( value === null || value === undefined ) {
173171 // Empty.
174172 } else if ( typeof value === 'function' ) {
175- addPlugin . apply ( null , arguments )
173+ addPlugin ( ... arguments )
176174 } else if ( typeof value === 'object' ) {
177175 if ( 'length' in value ) {
178176 addList ( value )
@@ -202,7 +200,7 @@ function unified() {
202200 addPlugin ( value )
203201 } else if ( typeof value === 'object' ) {
204202 if ( 'length' in value ) {
205- addPlugin . apply ( null , value )
203+ addPlugin ( ... value )
206204 } else {
207205 addPreset ( value )
208206 }
@@ -229,7 +227,7 @@ function unified() {
229227 var entry = find ( plugin )
230228
231229 if ( entry ) {
232- if ( plain ( entry [ 1 ] ) && plain ( value ) ) {
230+ if ( isPlainObj ( entry [ 1 ] ) && isPlainObj ( value ) ) {
233231 value = extend ( true , entry [ 1 ] , value )
234232 }
235233
@@ -355,7 +353,7 @@ function unified() {
355353 function executor ( resolve , reject ) {
356354 var file = vfile ( doc )
357355
358- pipeline . run ( processor , { file : file } , done )
356+ pipeline . run ( processor , { file} , done )
359357
360358 function done ( error ) {
361359 if ( error ) {
@@ -454,3 +452,7 @@ function assertDone(name, asyncName, complete) {
454452 )
455453 }
456454}
455+
456+ function vfile ( doc ) {
457+ return doc instanceof VFile ? doc : new VFile ( doc )
458+ }
0 commit comments