Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //filter will reemit the data if cb(err,pass) pass is truthy
  2. // reduce is more tricky
  3. // maybe we want to group the reductions or emit progress updates occasionally
  4. // the most basic reduce just emits one 'data' event after it has recieved 'end'
  5. var through = require('through')
  6. var Decoder = require('string_decoder').StringDecoder
  7. module.exports = split
  8. //TODO pass in a function to map across the lines.
  9. function split (matcher, mapper, options) {
  10. var decoder = new Decoder()
  11. var soFar = ''
  12. var maxLength = options && options.maxLength;
  13. if('function' === typeof matcher)
  14. mapper = matcher, matcher = null
  15. if (!matcher)
  16. matcher = /\r?\n/
  17. function emit(stream, piece) {
  18. if(mapper) {
  19. try {
  20. piece = mapper(piece)
  21. }
  22. catch (err) {
  23. return stream.emit('error', err)
  24. }
  25. if('undefined' !== typeof piece)
  26. stream.queue(piece)
  27. }
  28. else
  29. stream.queue(piece)
  30. }
  31. function next (stream, buffer) {
  32. var pieces = ((soFar != null ? soFar : '') + buffer).split(matcher)
  33. soFar = pieces.pop()
  34. if (maxLength && soFar.length > maxLength)
  35. stream.emit('error', new Error('maximum buffer reached'))
  36. for (var i = 0; i < pieces.length; i++) {
  37. var piece = pieces[i]
  38. emit(stream, piece)
  39. }
  40. }
  41. return through(function (b) {
  42. next(this, decoder.write(b))
  43. },
  44. function () {
  45. if(decoder.end)
  46. next(this, decoder.end())
  47. if(soFar != null)
  48. emit(this, soFar)
  49. this.queue(null)
  50. })
  51. }