npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-etl-splitfile

v1.0.2

Published

Splits gulp-etl Message Stream files into multiple files

Downloads

2

Readme

gulp-etl-splitfile

Split a single Message Stream file into multiple files. Ideal for chunking a stream into smaller pieces for manageability of file sizes or upload runs to database, or for "grouping" lines into files based on properties or values

This is a gulp-etl plugin, and as such it is a gulp plugin. gulp-etl plugins processes ndjson data streams/files which we call Message Streams and which are compliant with the Singer specification. Message Streams look like this:

{"type": "SCHEMA", "stream": "users", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}}}}
{"type": "RECORD", "stream": "users", "record": {"id": 1, "name": "Chris"}}
{"type": "RECORD", "stream": "users", "record": {"id": 2, "name": "Mike"}}
{"type": "SCHEMA", "stream": "locations", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}}}}
{"type": "RECORD", "stream": "locations", "record": {"id": 1, "name": "Philadelphia"}}
{"type": "STATE", "value": {"users": 2, "locations": 1}}

Usage

const splitFile = require('gulp-etl-splitfile').splitFile; // javascript
import { splitFile } from 'gulp-etl-splitfile';            // typescript

gulp-etl plugins accept a configObj as its first parameter. The configObj will contain any info the plugin needs.

Available configObj properties for this plugin:

  • index:number - The maximum number of lines in each new file. Cannot be combined with groupBy.
.pipe(splitFile({index:1000}))                // Split out a new file every 1000 lines
.pipe(splitFile({groupBy:'.type', index:2 })) // cause error by using groupBy and index together
.pipe(splitFile({}))                          // default (no options): split out a new file for every line
  • groupBy:string|array - Value(s) in lines to split lines between files; uses JSONSelect. Cannot be combined with index.
.pipe(splitFile({groupBy:'.type'}))                                     // group by (split lines to new files based on) the value of the "type" property of each line
.pipe(splitFile({groupBy:['.type', ".stream"]}))                        // group by `type` and then `stream`
.pipe(splitFile({groupBy:'.record .name'}))                             // group by `record.name` property)
.pipe(splitFile({groupBy:'.record ."Last Name", .type:val("STATE")' })) // group by `record.Last Name`, and/or by `type` (if it is equal to "STATE")
  • separator:string - Character(s) to separate sections of file names
// splitting `file.ndjson`
.pipe(splitFile({index:1000, separator:'_'}))      // -> `file_0.ndjson`, `file_1.ndjson`... (this is the default)
.pipe(splitFile({index:1000, separator:'-'}))      // -> `file-0.ndjson`, `file-1.ndjson`...
.pipe(splitFile({groupBy:'.type', separator:'-'})) // -> `file-SCHEMA.ndjson`, `file-RECORD.ndjson`...
.pipe(splitFile({groupBy:['.type', ".stream"]}))   // -> `file_SCHEMA_users.ndjson`, `file-RECORD_users.ndjson`...
  • timeStamp:boolean - Add a shortened string to all filenames based on the current time? use to keep successive runs from overwriting results from those before
.pipe(splitFile({index:1000, timeStamp:true }))    // -> `file_l4514_fe_0.ndjson`, `file_l4514_fe_1.ndjson`...

Quick Start

  • Dependencies:
    • git
    • nodejs - At least v6.3 (6.9 for Windows) required for TypeScript debugging
    • npm (installs with Node)
    • typescript - installed as a development dependency
  • Clone this repo and run npm install to install npm packages
  • Debug: with VScode use Open Folder to open the project folder, then hit F5 to debug. This runs without compiling to javascript using ts-node
  • Test: npm test or npm t
  • Compile to javascript: npm run build
  • Run using included test data (be sure to build first): gulp --gulpfile debug/gulpfile.ts

Testing

We are using Jest for our testing. Each of our tests are in the test folder.

  • Run npm test to run the test suites note: tests are currently broken

Notes

Note: This document is written in Markdown. We like to use Typora and Markdown Preview Plus for our Markdown work.