Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert codebase to typescript #51

Merged
merged 12 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .eslintrc

This file was deleted.

55 changes: 55 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:node/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["tsconfig.test.json"],
"sourceType": "module"
},
"settings": {
"import/resolver": {
"typescript": true,
"node": true
}
},
"plugins": [
"@typescript-eslint",
"mocha"
],
"env": {
"node": true,
"es6": true,
"mocha": true
},
"rules": {
"quote-props": ["error", "consistent"],
"mocha/no-skipped-tests": "error",
"mocha/no-exclusive-tests": "error",
"node/no-unpublished-import": [
"error", {
"allowModules": ["slow-stream"]
}
],
"node/no-unsupported-features/es-syntax": [
"error",
{
"version": ">=13.0.0",
"ignores": ["modules"]
}
],
"node/no-missing-import": [
"error", {
"allowModules": [],
"resolvePaths": ["/path/to/a/modules/directory"],
"tryExtensions": [".js", ".ts"]
}
]
}
}
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extension": ["ts"],
"node-option": ["loader=ts-node/esm"]
}
27 changes: 27 additions & 0 deletions .tools/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail

readonly PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."

rm -rf "${PROJECT_DIR}/dist"

cd "${PROJECT_DIR}"

echo "Building oleoduc (esm version)..."
tsc -p tsconfig.json
cat >"./dist/mjs/package.json" <<!EOF
{
"type": "module"
}
!EOF

echo "Building oleoduc (cjs version)..."
tsc -p tsconfig.cjs.json
cat >"./dist/cjs/package.json" <<!EOF
{
"type": "commonjs"
}
!EOF

cd -

6 changes: 0 additions & 6 deletions .tools/git-hooks/pre-commit

This file was deleted.

19 changes: 19 additions & 0 deletions .tools/hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail

readonly PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
readonly PRE_COMMIT_HOOK="${PROJECT_DIR}/.git/hooks/pre-commit"

cat <<'EOF' >"${PRE_COMMIT_HOOK}"
#!/usr/bin/env bash
set -euo pipefail
# Do not edit. This file has been generated by oleoduc

npm test
npm run lint
npm run build

EOF

chmod +x "${PRE_COMMIT_HOOK}"
echo "pre-push hooks installed in ${PRE_COMMIT_HOOK}"
69 changes: 34 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ oleoduc(

## compose(...streams, [options])

Same as oleoduc but without promise stuff.
Same as oleoduc but without promise stuff and stream composition capability

#### Parameters

Expand Down Expand Up @@ -381,7 +381,7 @@ oleoduc(

## mergeStreams(...streams, [options])

Allows streams to be merged into a single one.
Allows chunks of multiple streams to be processed in no particular order.

#### Parameters

Expand Down Expand Up @@ -432,8 +432,8 @@ await oleoduc(
Pipe streams together, forwards errors and returns a promisified stream.

It is same as nodejs
core [pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_source_transforms_destination_callback) but
with better error handling and stream composition capability.
core [pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_source_transforms_destination_callback)
but with better error handling.

If the last stream is readable, the returned stream will be iterable

Expand Down Expand Up @@ -554,6 +554,36 @@ Robert;Hue
`
```

Stream data as if it where a csv with options

```js
const { oleoduc, transformIntoCSV } = require("oleoduc");
const { Readable } = require("stream");
const { createWriteStream } = require("fs");

const source = Readable.from([{ firstname: "John", lastname: "Doe" }, { firstname: "Robert", lastname: "Hue" }]);

await oleoduc(
source,
transformIntoCSV({
sepatator: "|",
mapper: (v) => `"${v || ''}"`,//Values will be enclosed in double quotes
columns: {
fullname: (data) => `${data.firstName} ${data.lastName}`,
date: () => new Date().toISOString(),
},
}),
createWriteStream("/path/to/file")
);

// --> Output CSV file
`
fullname|date
John Doe|2021-03-12T21:34:13.085Z
Robert Hue|2021-03-12T21:34:13.085Z
`
```

## transformIntoJSON([options])

Allows data to be streamed as if it were a json string
Expand Down Expand Up @@ -582,7 +612,6 @@ await oleoduc(

// Json Output
'[{ user: "John Doe" }, { user: "Robert Hue" }]'

```

Stream data as if it where a json object with an array property inside
Expand All @@ -603,36 +632,6 @@ await oleoduc(
'{ other: "data", users: [{ user: "John Doe" }, { user: "Robert Hue" }] }'
```

Stream data as if it where a csv with options

```js
const { oleoduc, transformIntoCSV } = require("oleoduc");
const { Readable } = require("stream");
const { createWriteStream } = require("fs");

const source = Readable.from([{ firstname: "John", lastname: "Doe" }, { firstname: "Robert", lastname: "Hue" }]);

await oleoduc(
source,
transformIntoCSV({
sepatator: "|",
mapper: (v) => `"${v || ''}"`,//Values will be enclosed in double quotes
columns: {
fullname: (data) => `${data.firstName} ${data.lastName}`,
date: () => new Date().toISOString(),
},
}),
createWriteStream("/path/to/file")
);

// --> Output CSV file
`
fullname|date
John Doe|2021-03-12T21:34:13.085Z
Robert Hue|2021-03-12T21:34:13.085Z
`
```

## transformStream([options])

Allows chunks of a sub-stream to be streamed as if each was part of the source
Expand Down
15 changes: 0 additions & 15 deletions index.js

This file was deleted.

9 changes: 0 additions & 9 deletions lib/compose.js

This file was deleted.

7 changes: 0 additions & 7 deletions lib/filterData.js

This file was deleted.

7 changes: 0 additions & 7 deletions lib/utils/decorateWithAsyncIterator.js

This file was deleted.

Loading
Loading