Skip to content

feat!: implement with unjs template #3

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[*.js]
indent_style = space
indent_size = 2

[{package.json,*.yml,*.cjson}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
dist
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["eslint-config-unjs"],
"rules": {}
}
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm build
- run: pnpm vitest --coverage
- uses: codecov/codecov-action@v3
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
coverage
dist
types
.vscode
.DS_Store
.eslintcache
*.log*
*.conf*
*.env*
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
6 changes: 3 additions & 3 deletions LICENSE
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) 2017 Pooya Parsa <[email protected]>
Copyright (c)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
72 changes: 53 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,72 @@
# items-promise
Bare minimum async methods using promises. (Inspired by [items](https://www.npmjs.com/package/items))

```bash
>_ yarn add items-promise
```
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Github Actions][github-actions-src]][github-actions-href]
[![Codecov][codecov-src]][codecov-href]

> Bare minimum async methods using promises. (Inspired by [items](https://www.npmjs.com/package/items))

## Usage

OR using NPM
Install package:

```bash
>_ npm install items-promise
```sh
# npm
npm install items-promise

# yarn
yarn add items-promise

# pnpm
pnpm install items-promise
```

Import:

```js
const { serial, parallel } = require('items-promise')
// OR
import { serial, parallel } from 'items-promise'
// ESM
import { serial, parallel } from "items-promise"

// CommonJS
const { serial, parallel } = require("items-promise")
```

# Usage
`tasks` should be always an array and `fn` should be a function witch returns a **Promise** object.
`tasks` should be always an array and `fn` should be a function which returns a `Promise`.

## serial(tasks, fn)
### serial(tasks, fn)

Run tasks one by one by calling `fn(task, previous)` in a promise chain.

Return value is of type `Promise<*>` which resolves to the **last** fn result.
Return value is of type `Promise<*>` which resolves to the **last** `fn` result.

## parallel(tasks, fn)
### parallel(tasks, fn)

Run all tasks in parallel by calling `fn(tasks)` and await using `Promise.all`.

Return value is of type `Promise<*[]>` which resolves to results of **all** fns in an array.
Return value is of type `Promise<*[]>` which resolves to results of **all** `fn`s in the array.

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

Made with 💛

Published under [MIT License](./LICENSE).

# License
Released under The MIT [LICENSE](./LICENSE)
<!-- Badges -->

Copyright (c) 2017 Pooya Parsa
[npm-version-src]: https://img.shields.io/npm/v/items-promise?style=flat-square
[npm-version-href]: https://npmjs.com/package/items-promise
[npm-downloads-src]: https://img.shields.io/npm/dm/items-promise?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/items-promise
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/items-promise/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/items-promise/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/items-promise/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/items-promise
13 changes: 0 additions & 13 deletions lib/index.js

This file was deleted.

43 changes: 40 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,45 @@
"name": "items-promise",
"version": "1.0.0",
"description": "Bare minimum async methods using promises",
"main": "lib/index.js",
"repository": "https://github.com/pi0/items-promise",
"author": "Pooya Parsa <[email protected]>",
"license": "MIT"
"contributors": [
"Nozomu Ikuta <[email protected]>"
],
Comment on lines +6 to +8
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, only if you are fine.

"repository": "unjs/items-promise",
"license": "MIT",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm run build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && vitest run --coverage"
},
"devDependencies": {
"@vitest/coverage-c8": "^0.27.2",
"changelogen": "^0.4.1",
"eslint": "^8.23.0",
"eslint-config-unjs": "^0.1.0",
"prettier": "^2.8.3",
"typescript": "^4.8.2",
"unbuild": "^1.1.1",
"vitest": "^0.27.2"
},
"packageManager": "[email protected]"
}
Loading