Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 00a58a6

Browse files
committedFeb 28, 2024
Updated repository so that it can be published to npm. Added GitHUb action for package release
1 parent f13b370 commit 00a58a6

File tree

10 files changed

+140
-67
lines changed

10 files changed

+140
-67
lines changed
 

‎.github/workflows/release-package.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish to GitHub Package Registry
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
permissions:
9+
packages: read
10+
contents: read
11+
12+
jobs:
13+
build-and-test:
14+
name: Run Jest Unit Tests
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
- run: npm ci
22+
- run: npm test
23+
24+
publish-gpr:
25+
name: Publish to GitHub Package Registry
26+
needs: build-and-test
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
30+
packages: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
36+
registry-url: https://npm.pkg.github.com/
37+
scope: @lordofdestiny
38+
access: public
39+
- run: npm ci
40+
- run: npm publish
41+
env:
42+
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
43+

‎.github/workflows/static.yml

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# Simple workflow for deploying static content to GitHub Pages
2-
name: Generate and deploy TypeDoc to GitHub Pages
1+
name: Generate Docs for GitHub Pages
32

43
on:
5-
# Runs on pushes targeting the default branch
64
push:
75
branches: ["main"]
8-
9-
# Allows you to run this workflow manually from the Actions tab
106
workflow_dispatch:
117

128
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
@@ -22,7 +18,6 @@ concurrency:
2218
cancel-in-progress: false
2319

2420
jobs:
25-
# Single deploy job since we're just deploying
2621
deploy:
2722
environment:
2823
name: github-pages
@@ -34,13 +29,15 @@ jobs:
3429
- name: Setup Node.js environment
3530
uses: actions/setup-node@v4.0.2
3631
with:
37-
# Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.
38-
node-version: 18
32+
node-version: 20
3933
cache: 'npm'
4034
- run: npm ci
41-
- run: npm run docs
42-
- run: npm run coverage:badges
43-
- run: node scripts/extract-coverage.js >> $GITHUB_ENV
35+
- name: Generate Docs
36+
run: npm run docs
37+
- name: Extract coverage
38+
run: |
39+
npm run coverage:badges
40+
node scripts/extract-coverage.js >> $GITHUB_ENV
4441
- name: Create coverage badges
4542
uses: schneegans/dynamic-badges-action@v1.7.0
4643
with:
@@ -61,7 +58,6 @@ jobs:
6158
- name: Upload artifact
6259
uses: actions/upload-pages-artifact@v3
6360
with:
64-
# Upload entire repository
6561
path: './docs'
6662
- name: Deploy to GitHub Pages
6763
id: deployment

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
dist
33
coverage
4-
docs
4+
docs
5+
*.tgz

‎.npmignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.idea/
2+
scripts/
3+
__tests__/
4+
coverage/
5+
docs/
6+
.github/
7+
.gitattributes
8+
tsconfig.*
9+
typedoc.json
10+
jest.config.js
11+
*.tgz
12+
!scripts/preinstall.js
13+
.npmrc

‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://npm.pkg.github.com/:_authToken=${NPM_SECRET}

‎README.md

+50-47
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,61 @@ and Rust's <a href="https://doc.rust-lang.org/std/iter/trait.Iterator.html" targ
1717
Library is still in development and not yet ready for production use. It's mostly feature complete,
1818
but there are still some missing methods and some methods, like `cycle` and `reverse`.
1919

20-
Library is written in TypeScript and is intended to be used with TypeScript. It's not yet published.
20+
Library is written in TypeScript and compiled to ES6. You can use it in both Node.js and the browser,
21+
with both TypeScript and JavaScript.
2122

22-
Focus of the library was more on the API design and less on performance.
23+
All methods are lazy and return a new Stream object. Even so,
24+
focus of the library was more on the API design and less on performance.
2325

24-
All methods are lazy and return a new Stream object.
26+
Library is heavily tested with Jest.
2527

26-
All methods are heavily tested with Jest.
28+
## Examples
29+
30+
```typescript
31+
import { Stream } from 'streams-ts';
32+
33+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
34+
35+
const result = Stream.from(arr)
36+
.filter(x => x % 2 === 0)
37+
.map(x => x * 2)
38+
.toArray();
39+
40+
console.log(result); // [4, 8, 12, 16, 20]
41+
42+
const result2 = Stream.from(arr)
43+
.filter(x => x % 2 === 0)
44+
.map(x => x * 2)
45+
.reduce((acc, x) => acc + x, 0);
46+
47+
console.log(result2); // 60
48+
49+
const result3 = Stream.from(arr)
50+
.filter(x => x % 2 === 0)
51+
.map(x => x * 2)
52+
.findFirst();
53+
54+
console.log(result3); // 4
55+
56+
const result4 = Stream.from(arr)
57+
.chunk(2)
58+
.toMap()
59+
60+
console.log(result4); // Map { 1 => 2, 3 => 4, 5 => 6, 7 => 8, 9 => 10 }
61+
```
2762

2863
## Installation
2964

30-
Library is not yet published. You can always download the source code and copy it to your project.
65+
To install the library, you can use npm, to install from the public npm registry:
66+
67+
```npm install streams-ts```
68+
69+
or from the GitHub repository:
70+
71+
```npm install lordofdestiny/streams-ts```
72+
3173

32-
[comment]: <> (```npm install streams-ts```)
74+
For mor examples, check the tests or the documentation.
3375

3476
## Building
3577

@@ -48,7 +90,6 @@ If you want, you can also build the library in watch mode:
4890
If you decide to clone the repository, you can run tests with:
4991

5092
```
51-
npm install
5293
npm test
5394
```
5495

@@ -64,7 +105,7 @@ This opens a browser with coverage report.
64105

65106
## Documentation
66107

67-
#### *_[Official documentation is avilable at here](https://streams-ts.github.io/streams-ts/)_*
108+
#### *_[Official documentation is avilable at here](https://lordofdestiny.github.io/streams-ts/)_*
68109

69110
You can also generate documentation from the source code by using:
70111

@@ -75,7 +116,6 @@ After that, you can open `docs/index.html` in your browser or by running
75116
```npm run docs:open```
76117

77118
You can check the tests for more examples.
78-
79119

80120
## Clean build results
81121

@@ -89,41 +129,4 @@ You can check the tests for more examples.
89129

90130
### Coverage
91131

92-
```npm run clean:coverage```
93-
94-
## Examples
95-
96-
```typescript
97-
import { Stream } from 'streams-ts';
98-
99-
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
100-
101-
const result = Stream.from(arr)
102-
.filter(x => x % 2 === 0)
103-
.map(x => x * 2)
104-
.toArray();
105-
106-
console.log(result); // [4, 8, 12, 16, 20]
107-
108-
const result2 = Stream.from(arr)
109-
.filter(x => x % 2 === 0)
110-
.map(x => x * 2)
111-
.reduce((acc, x) => acc + x, 0);
112-
113-
console.log(result2); // 60
114-
115-
const result3 = Stream.from(arr)
116-
.filter(x => x % 2 === 0)
117-
.map(x => x * 2)
118-
.findFirst();
119-
120-
console.log(result3); // 4
121-
122-
const result4 = Stream.from(arr)
123-
.slide(2)
124-
.toMap()
125-
126-
console.log(result4); // Map { 1 => 2, 3 => 4, 5 => 6, 7 => 8, 9 => 10 }
127-
```
128-
129-
For mor examples, check the tests or the documentation.
132+
```npm run clean:coverage```

‎package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"name": "streams-ts",
33
"version": "1.0.0",
4+
"main": "dist/index.js",
5+
"types": "dist/index.d.ts",
6+
"author": "lordofdestiny",
7+
"license": "MIT",
48
"description": "Streams library for TS",
5-
"main": "index.js",
69
"scripts": {
10+
"preinstall": "node scripts/preinstall.js",
11+
"prepublish": "npm run build",
712
"build": "tsc --build tsconfig.build.json && tsc-alias",
813
"build:watch": "concurrently --kill-others \"tsc --build tsconfig.build.json --watch\" \"tsc-alias -w\"",
914
"test": "jest",
@@ -18,14 +23,21 @@
1823
"clean:docs": "ts-node scripts/clean.ts docs",
1924
"clean": "ts-node scripts/clean.ts dist coverage docs"
2025
},
21-
"keywords": ["typescript", "npm", "Stream API", "streams", "streams-ts"],
26+
"keywords": [
27+
"typescript",
28+
"npm",
29+
"Stream API",
30+
"streams",
31+
"streams-ts"
32+
],
2233
"homepage": "lordofdestiny.github.io/streams-ts",
2334
"repository": {
2435
"type": "git",
25-
"url": "github:lordofdestiny/streams-ts.git"
36+
"url": "git+https://github.com/lordofdestiny/streams-ts.git"
37+
},
38+
"publishConfig": {
39+
"access": "public"
2640
},
27-
"author": "lordofdestiny",
28-
"license": "MIT",
2941
"devDependencies": {
3042
"@jest/globals": "^29.7.0",
3143
"@tsconfig/node18": "^18.2.2",

‎scripts/preinstall.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Thanks for installing me!")

‎tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"$schema": "https://json.schemastore.org/tsconfig",
44
"compilerOptions": {
55
"lib": [
6-
"ES2023",
6+
"ES2015",
7+
"ES2015.Iterable",
8+
"ES2015.Collection"
79
],
810
"declaration": true,
911
"module": "NodeNext",

0 commit comments

Comments
 (0)
Please sign in to comment.