UNPKG

newline-async-iterator

Version:

Line-by-line async iterator for the browser and node

3 lines (2 loc) 1.71 kB
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).newlineAsyncIterator=n()}(this,function(){"use strict";var e=function(e){for(var n,t="",r=e.length,o=0;o<r;o++)n=e[o],t+=String.fromCharCode(n>251&&n<254&&o+5<r?1073741824*(n-252)+(e[++o]-128<<24)+(e[++o]-128<<18)+(e[++o]-128<<12)+(e[++o]-128<<6)+e[++o]-128:n>247&&n<252&&o+4<r?(n-248<<24)+(e[++o]-128<<18)+(e[++o]-128<<12)+(e[++o]-128<<6)+e[++o]-128:n>239&&n<248&&o+3<r?(n-240<<18)+(e[++o]-128<<12)+(e[++o]-128<<6)+e[++o]-128:n>223&&n<240&&o+2<r?(n-224<<12)+(e[++o]-128<<6)+e[++o]-128:n>191&&n<224&&o+1<r?(n-192<<6)+e[++o]-128:n);return t};if("undefined"!=typeof TextDecoder){var n=new TextDecoder("utf8");e=function(e){return n.decode(e)}}var t=e;var r=/\r?\n|\r/g,o="undefined"==typeof window?global:window,i=void 0===o.Symbol?{asyncIterator:void 0}:o.Symbol;return function(e){var n,o,u,f=[],a="",l=!1,d=i.asyncIterator?e[i.asyncIterator]():e;function c(){return new Promise(function(e,n){d.next().then(function(o){o.done?l=!0:a+=t(o.value);var i=a.length>0?a[a.length-1]:"";if(l||"\r"!==i&&"\n"!==i){var u=a.split(r);a=u.pop(),u.forEach(function(e){return f.unshift(e)}),l&&a.length>0&&(f.unshift(a),a="")}if(f.length>0){var d=f.pop();return l&&0===f.length&&0===d.length?e({value:null,done:!0}):e({value:d,done:!1})}if(l)return e({value:null,done:!0});c().then(e).catch(n)})})}return n={next:function(){return c()}},o=i.asyncIterator,u=function(){return this},o in n?Object.defineProperty(n,o,{value:u,enumerable:!0,configurable:!0,writable:!0}):n[o]=u,n}}); //# sourceMappingURL=newline-async-iterator.min.cjs.map