UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 4.61 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import e from"./../../utils/define-nonenumerable-read-only-property.js";import t from"./../../vendor/process.js";import i from"./../../vendor/readable-stream.js";import r from"./../../utils/copy.js";import o from"./../../utils/inherit.js";import n from"./../../utils/define-nonenumerable-property.js";import s from"./../../buffer/ctor.js";import a from"./../../assert/is-plain-object.js";import p from"./../../assert/has-own-property.js";import d from"./../../assert/is-boolean.js";import l from"./../../assert/is-nonnegative-number.js";import f from"./../../assert/is-string.js";import m from"./../../assert/is-regexp.js";import u from"./../../vendor/debug.js";import h from"./../../buffer/from-string.js";var b=!1,c=null,g=!1,j=!1,w=null,v={objectMode:b,encoding:c,allowHalfOpen:g,writableObjectMode:j,sep:w},y=a,O=p,_=d.isPrimitive,M=l.isPrimitive,x=f.isPrimitive,S=m;function E(e,t){return y(t)?!O(t,"sep")||(e.sep=t.sep,x(e.sep)||S(e.sep))?O(t,"objectMode")&&(e.objectMode=t.objectMode,!_(e.objectMode))?new TypeError("invalid option. `objectMode` option must be a boolean primitive. Option: `"+e.objectMode+"`."):O(t,"writableObjectMode")&&(e.writableObjectMode=t.writableObjectMode,!_(e.writableObjectMode))?new TypeError("invalid option. `writableObjectMode` option must be a boolean primitive. Option: `"+e.writableObjectMode+"`."):O(t,"encoding")&&(e.encoding=t.encoding,!x(e.encoding))?new TypeError("invalid option. `encoding` option must be a string primitive. Option: `"+e.encoding+"`."):O(t,"allowHalfOpen")&&(e.allowHalfOpen=t.allowHalfOpen,!_(e.allowHalfOpen))?new TypeError("invalid option. `allowHalfOpen` option must be a boolean primitive. Option: `"+e.allowHalfOpen+"`."):O(t,"highWaterMark")&&(e.highWaterMark=t.highWaterMark,!M(e.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+e.highWaterMark+"`."):null:new TypeError("invalid option. `sep` option must be either a primitive string or a regular expression. Option: `"+e.sep+"`."):new TypeError("invalid argument. Options must be an object. Value: `"+t+"`.")}var T=u,k=T("split-stream"),H=h;function I(e,t){return"utf8"===t||"buffer"===t?e:(e=H(e),t?e.toString(t):e.toString())}var W=i.Transform,P=r,N=o,C=n,J=e,V=s,R=v,A=E,F=k,q=I,z=/\r?\n/;function B(e,t,i){var r,o,n,s;if(this._idx+=1,F("Received a new chunk. Chunk: %s. Encoding: %s. Index: %d.",e.toString(),t,this._idx),"buffer"===t?e=e.toString():"utf8"!==t&&(e=(e=new V(e,t)).toString("utf8")),r=e.split(this._sep),F("Splits: %s. Index: %d.",JSON.stringify(r),this._idx),n=r.length-1,F("%s splits. Index: %d.",n,this._idx),0===n)F("No splits. Index: %d.",this._idx),this._buffer+=r[n];else{for(F("Processing splits. Index: %d.",this._index),o=this._buffer+r[0],o=q(o,t),F("Split %d: %s. Index: %d.",0,o.toString(),this._idx),this.push(o,t),s=1;s<n;s++)o=q(r[s],t),F("Split %d: %s. Index: %d.",s,o.toString(),this._idx),this.push(o,t);F("Remaining split: %s.",r[n].toString()),this._buffer=r[n]}i()}function D(e){var t=this._buffer;t&&(F("Processing final split..."),t=q(t,this._encoding),this.push(t,this._encoding)),F("Flushing the stream..."),e()}function G(e){var i;return this._destroyed?(F("Attempted to destroy an already destroyed stream."),this):(i=this,this._destroyed=!0,t.nextTick((function(){e&&(F("Stream was destroyed due to an error. Error: %s.",JSON.stringify(e)),i.emit("error",e));F("Closing the stream..."),i.emit("close")})),this)}function K(e){var t,i;if(!(this instanceof K))return arguments.length?new K(e):new K;if(t=P(R),arguments.length&&(i=A(t,e)))throw i;return t.readableObjectMode=!0,t.decodeStrings=!1,F("Creating a transform stream configured with the following options: %s.",JSON.stringify(t)),W.call(this,t),J(this,"_sep",null===t.sep?z:t.sep),C(this,"_destroyed",!1),J(this,"_encoding",t.encoding),C(this,"_buffer",""),C(this,"_idx",-1),this}N(K,W),J(K.prototype,"_transform",B),J(K.prototype,"_flush",D),J(K.prototype,"destroy",G);var L=a,Q=r,U=K;function X(e){var t;if(arguments.length){if(!L(e))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");t=Q(e)}else t={};return t.objectMode=!0,new U(t)}var Y=a,Z=r,$=K;function ee(e){var t;if(arguments.length){if(!Y(e))throw new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");t=Z(e)}else t={};return i;function i(){return new $(t)}}var te=e,ie=K,re=X,oe=ee;te(ie,"objectMode",re),te(ie,"factory",oe);export default ie; //# sourceMappingURL=split.js.map