Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nutgaard/data-pack
Utility pack for working with random data
https://github.com/nutgaard/data-pack
Last synced: about 2 months ago
JSON representation
Utility pack for working with random data
- Host: GitHub
- URL: https://github.com/nutgaard/data-pack
- Owner: nutgaard
- Created: 2021-11-25T00:52:50.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T07:49:12.000Z (almost 2 years ago)
- Last Synced: 2024-09-22T12:04:53.829Z (4 months ago)
- Language: TypeScript
- Size: 43.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Data-pack
Utility pack for working with random data
## File utils
Simple wrapper around `fs` and `fs/promises`.
```typescript
function read(path: string): Promise;
function readSync(path: string): string;
function readJSON(path: string): Promise;
function readJSONSync(path: string): Promise;function write(path: string, content: any): Promise;
function writeSync(path: string, content: any): void;
function withWriteStream(path: string, block: (stream: WriteStream) => void): void;
```## CSV
Utilities for parsing and writing CSV files
```typescript
function* parseCSV(content: string, delimiter: string = ''): Generator, void>;
function* parseCSVSync(content: string, delimiter: string = ''): Array>;
function* parseCSVToFlow(content: string, delimiter: string = ''): GeneratorFlow>;
```## JSON
Utilities for parsing and writing JSON
```typescript
function serialize(content: any): string;
function deserialize(content: string): T;
```## KeyValue (KV)
Utilities for parsing and writing in key-value pairs
```typescript
function writeKVSync(object: object, delimiters: KvDelimiters): string;
function parseKVSync(content: string, delimiters: KvDelimiters): T;
```## Generator flows
Utilities for working with generators as if they are arrays
```typescript
// Creation
const flow = GeneratorFlow.ofArray([1, 2, 3, 4]);
const numFlow = GeneratorFlow.ofArray([5, 6]);
const otherFlow = new GeneratorFlow(function* () {
yield 'a';
yield 'b';
yield 'c';
yield 'd';
});// Stream functions
flow.skipWhile((it) => it < 2); // Flow[3,4]
flow.takeWhile((it) => it < 2); // Flow[1]
flow.skip(2); // Flow[3,4]
flow.tail(); // Flow[2,3,4]
flow.take(2); // Flow[1,2]
flow.map((it) => it * 2); // Flow[2,4,6,8]
flow.flatMap((it) => [it * 2]); // Flow[2,4,6,8]
flow.filter((it) => it % 2 == 0); // Flow[2,4]
flow.zip(otherFlow); // Flow[[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']]
flow.cartesianProduct(otherFlow); // Flow[[1, 'a'], [1, 'b'], [1, 'c'], [1, 'd'], [2, 'a'], ... [4, 'd']]
flow.concat(otherFlow); // Flow[1, 2, 3, 4, 5, 6]
flow.peek(console.log); // Flow[1, 2, 3, 4]
flow.reduce(add, 0); // 10
flow.size(); // 4
flow.toArray(); // [1, 2, 3, 4]
flow.toSet(); // Set<1, 2, 3, 4>
```