{"id":13526535,"url":"https://github.com/dominictarr/split","last_synced_at":"2025-04-01T07:32:53.953Z","repository":{"id":4476905,"uuid":"5615862","full_name":"dominictarr/split","owner":"dominictarr","description":null,"archived":true,"fork":false,"pushed_at":"2019-07-02T12:29:19.000Z","size":125,"stargazers_count":347,"open_issues_count":7,"forks_count":39,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-09-07T02:19:37.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dominictarr.png","metadata":{"files":{"readme":"readme.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-30T14:20:09.000Z","updated_at":"2023-11-10T15:21:05.000Z","dependencies_parsed_at":"2022-09-19T03:31:03.183Z","dependency_job_id":null,"html_url":"https://github.com/dominictarr/split","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fsplit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fsplit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fsplit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominictarr%2Fsplit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominictarr","download_url":"https://codeload.github.com/dominictarr/split/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219000491,"owners_count":16422248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:31.139Z","updated_at":"2024-11-02T11:31:18.219Z","avatar_url":"https://github.com/dominictarr.png","language":"JavaScript","readme":"# Split (matcher)\n\n[![build status](https://secure.travis-ci.org/dominictarr/split.png)](http://travis-ci.org/dominictarr/split)\n\nBreak up a stream and reassemble it so that each line is a chunk. matcher may be a `String`, or a `RegExp`\n\nExample, read every line in a file ...\n\n``` js\n  fs.createReadStream(file)\n    .pipe(split())\n    .on('data', function (line) {\n      //each chunk now is a separate line!\n    })\n\n```\n\n`split` takes the same arguments as `string.split` except it defaults to '/\\r?\\n/' instead of ',', and the optional `limit` parameter is ignored.\n[String#split](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split)\n\n`split` takes an optional options object on its third argument.\n\n``` js\n  split(matcher, mapper, options)\n```\n\nValid options:\n\n* maxLength - The maximum buffer length without seeing a newline or `matcher`,\n  if a single line exceeds this, the split stream will emit an error.\n\n``` js\n  split(JSON.parse, null, { maxLength: 2})\n```\n\n* trailing - By default the last buffer not delimited by a newline or `matcher` will be emitted. To prevent this set `options.trailing` to `false`.\n\n``` js\n  split(JSON.parse, null, { trailing: false })\n```\n\n## keep matched splitter\n\nAs with `String#split`, if you split by a regular expression with a matching group,\nthe matches will be retained in the collection.\n\n```\nstdin\n.pipe(split(/(\\r?\\n)/))\n... //lines + separators.\n```\n\n\n# NDJ - Newline Delimited Json\n\n`split` accepts a function which transforms each line.\n\n``` js\nfs.createReadStream(file)\n  .pipe(split(JSON.parse))\n  .on('data', function (obj) {\n    //each chunk now is a a js object\n  })\n  .on('error', function (err) {\n    //syntax errors will land here\n    //note, this ends the stream.\n  })\n```\n\n# License\n\nMIT\n","funding_links":[],"categories":["Repository","JavaScript","Modules","模块"],"sub_categories":["Streams","Stream","数据流-Stream"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fsplit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominictarr%2Fsplit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominictarr%2Fsplit/lists"}