-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start with piqure to provide and inject
- Loading branch information
0 parents
commit 24bb283
Showing
13 changed files
with
5,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:import/errors', | ||
'plugin:import/warnings', | ||
'plugin:import/typescript', | ||
], | ||
plugins: ['prettier', '@typescript-eslint'], | ||
rules: { | ||
quotes: ['error', 'single', { avoidEscape: true }], | ||
'comma-dangle': [ | ||
'error', | ||
{ | ||
arrays: 'always-multiline', | ||
objects: 'always-multiline', | ||
imports: 'always-multiline', | ||
exports: 'always-multiline', | ||
functions: 'never', | ||
}, | ||
], | ||
'import/order': [ | ||
'error', | ||
{ | ||
alphabetize: { | ||
order: 'asc', | ||
caseInsensitive: true, | ||
}, | ||
'newlines-between': 'always', | ||
}, | ||
], | ||
'prettier/prettier': [ | ||
'error', | ||
{ | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
printWidth: 140, | ||
}, | ||
], | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: { | ||
alwaysTryTypes: true, | ||
}, | ||
}, | ||
'import/core-modules': ['sinon'], | ||
}, | ||
parserOptions: { | ||
parser: '@typescript-eslint/parser', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['**/*.ts', '**/*.tsx'], | ||
rules: { | ||
'no-unused-vars': ['off'], | ||
'no-undef': ['off'], | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Node CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-2022, ubuntu-latest] | ||
node-version: [18.x] | ||
steps: | ||
- run: git config --global core.autocrlf false | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: node check | ||
run: | | ||
npm ci | ||
npm run eslint:ci | ||
npm run build | ||
npm run test:ci | ||
deploy: | ||
if: startsWith(github.event.ref, 'refs/tags/') | ||
needs: build | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
registry-url: 'https://registry.npmjs.org' | ||
- name: deploy | ||
run: | | ||
PACKAGE_VERSION=$(cat package.json|grep version|head -1|awk -F: '{ print $2 }'|sed 's/[", ]//g') | ||
echo "Package: $PACKAGE_VERSION" | ||
echo "Tag: $GITHUB_REF_NAME" | ||
if [ "$PACKAGE_VERSION" != "$GITHUB_REF_NAME" ]; then echo "$PACKAGE_VERSION and $GITHUB_REF_NAME are not the same, skipping"; exit 1; fi | ||
echo "Publishing $PACKAGE_VERSION …" | ||
npm ci | ||
npm run build | ||
npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/node_modules/ | ||
/.idea/ | ||
/coverage/ | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.editorconfig | ||
/.eslintignore | ||
/.eslintrc.js | ||
/.github | ||
/.idea | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2023 Anthony Rey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Piqure | ||
|
||
Just a dependency injection system in JavaScript. | ||
|
||
## Prerequisites | ||
|
||
* [Node](https://nodejs.org/) LTS | ||
|
||
## Install | ||
|
||
```shell | ||
npm i piqure | ||
``` | ||
|
||
## Usage | ||
|
||
Classic usage: | ||
|
||
```typescript | ||
import { key, piqure } from './Piqure'; | ||
|
||
const { provide, inject } = piqure(); | ||
|
||
// Create an injection key with a type and a description | ||
const KEY_TO_INJECT = key<string>('Key to inject'); | ||
|
||
// Register a text using provide | ||
provide(KEY_TO_INJECT, 'Injected text'); | ||
|
||
// Use your text | ||
const injected = inject(KEY_TO_INJECT); | ||
|
||
console.log(injected); // Injected text | ||
``` | ||
|
||
Attach piqure to the map you want: | ||
|
||
```typescript | ||
import { piqure } from './Piqure'; | ||
|
||
const memory = new Map(); | ||
|
||
const { provide, inject } = piqure(memory); // Now, the injected values will be inside "memory" | ||
|
||
// […] | ||
``` | ||
|
||
Attach piqure to a wrapper like `window`: | ||
|
||
```typescript | ||
import { piqureWrapper } from './Piqure'; | ||
|
||
const { provide, inject } = piqureWrapper(window, 'piqure'); // This will reuse or create a "piqure" field | ||
|
||
// […] | ||
``` | ||
|
||
To expose `provide` and `inject` globally with the `window` (if you're in a browser environment), just create a file in your project with: | ||
|
||
```typescript | ||
import { piqureWrapper } from './Piqure'; | ||
|
||
const { provide, inject } = piqureWrapper(window, 'piqure'); | ||
|
||
export { provide, inject }; | ||
``` | ||
|
||
## Contribute | ||
|
||
Install with: | ||
|
||
```shell | ||
npm i | ||
``` | ||
|
||
Launch tests with: | ||
|
||
```shell | ||
npm test | ||
``` | ||
|
||
Then start coding and don't hesitate to send PR. |
Oops, something went wrong.