Skip to content

Commit 059bdb5

Browse files
committed
feat: initial
1 parent d533901 commit 059bdb5

25 files changed

+5876
-0
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/coverage/
2+
/dist/

.eslintrc.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@djaler/typescript'],
4+
parserOptions: {
5+
project: './tsconfig.lint.json',
6+
},
7+
settings: {
8+
'import/resolver': {
9+
typescript: {},
10+
},
11+
},
12+
rules: {
13+
'import/no-extraneous-dependencies': ['error', {
14+
devDependencies: [
15+
'src/**/*.spec.ts',
16+
'tests/**/*.ts',
17+
'vite.config.js',
18+
],
19+
}],
20+
21+
'no-void': 'off',
22+
},
23+
};

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.js text eol=lf
2+
*.ts text eol=lf

.github/workflows/checks.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out Git repository
15+
uses: actions/checkout@v2
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 16.9
20+
- name: Cache pnpm modules
21+
uses: actions/cache@v2
22+
with:
23+
path: ~/.pnpm-store
24+
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
25+
restore-keys: ${{ runner.os }}-
26+
- name: Install dependencies
27+
run: corepack pnpm install
28+
- name: Run build
29+
run: npm run build
30+
31+
lint:
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- name: Check out Git repository
36+
uses: actions/checkout@v2
37+
- name: Set up Node.js
38+
uses: actions/setup-node@v2
39+
with:
40+
node-version: 16.9
41+
- name: Cache pnpm modules
42+
uses: actions/cache@v2
43+
with:
44+
path: ~/.pnpm-store
45+
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
46+
restore-keys: ${{ runner.os }}-
47+
- name: Install dependencies
48+
run: corepack pnpm install
49+
- name: Run linter
50+
uses: reviewdog/action-eslint@v1
51+
with:
52+
reporter: github-check
53+
54+
test:
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- name: Check out Git repository
59+
uses: actions/checkout@v2
60+
- name: Set up Node.js
61+
uses: actions/setup-node@v2
62+
with:
63+
node-version: 16.9
64+
- name: Cache pnpm modules
65+
uses: actions/cache@v2
66+
with:
67+
path: ~/.pnpm-store
68+
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
69+
restore-keys: ${{ runner.os }}-
70+
- name: Install dependencies
71+
run: corepack pnpm install
72+
- name: Run tests
73+
run: npm run test

.github/workflows/release.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out Git repository
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Set up Node.js
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: 16.9
21+
- name: Cache pnpm modules
22+
uses: actions/cache@v2
23+
with:
24+
path: ~/.pnpm-store
25+
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
26+
restore-keys: ${{ runner.os }}-
27+
- name: Install dependencies
28+
run: corepack pnpm install
29+
- uses: filipstefansson/set-npm-token-action@v1
30+
with:
31+
token: ${{ secrets.NPM_TOKEN }}
32+
- name: Build package
33+
run: npm run build
34+
- name: Publish package
35+
run: npm run publish
36+
- name: Create github release
37+
run: npm run release:github
38+
env:
39+
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
coverage/
3+
dist/
4+
node_modules/

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enable-pre-post-scripts=true

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Kirill Romanov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
[![npm](https://img.shields.io/npm/v/vue-use-route-query?style=for-the-badge)](https://www.npmjs.com/package/vue-use-route-query)
2+
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/vue-use-route-query?style=for-the-badge)](https://bundlephobia.com/result?p=vue-use-route-query)
3+
4+
# Vue Use Route Query
5+
6+
> A tiny Vue composable function to create a ref synced with vue router query.
7+
8+
## Install
9+
10+
```sh
11+
npm install --save vue-use-route-query
12+
```
13+
14+
or
15+
16+
```sh
17+
yarn add vue-use-route-query
18+
```
19+
20+
or
21+
22+
```sh
23+
pnpm install vue-use-route-query
24+
```
25+
26+
## Usage
27+
28+
Simple usage with a string parameter without any transformations
29+
30+
```ts
31+
import { defineComponent } from '@vue/composition-api'
32+
import { useRouteQuery } from 'vue-use-route-query'
33+
34+
export default defineComponent({
35+
setup() {
36+
const foo = useRouteQuery('foo', ''); // Ref<string>
37+
const bar = useRouteQuery('bar', null); // Ref<string | null>
38+
39+
return {
40+
foo,
41+
bar,
42+
}
43+
}
44+
})
45+
```
46+
47+
More complex usage with a transformer function
48+
49+
```ts
50+
import { defineComponent } from '@vue/composition-api'
51+
import { useRouteQuery, RouteQueryTransformer } from 'vue-use-route-query'
52+
53+
export default defineComponent({
54+
setup() {
55+
// This transformer will reverse the string because why not
56+
const reverseTransformer: RouteQueryTransformer<string> = {
57+
fromQuery(query) {
58+
return query.split('').reverse().join('');
59+
},
60+
toQuery(value) {
61+
return value?.split('').reverse().join('');
62+
}
63+
}
64+
65+
const foo = useRouteQuery('foo', '', reverseTransformer);
66+
67+
foo.value = 'bar'; // Results in 'foo=rab' in the query
68+
69+
return {
70+
foo,
71+
}
72+
}
73+
})
74+
```
75+
76+
A several transformers provided by the library out of the box:
77+
78+
* `integerTransformer`
79+
```js
80+
const foo = useRouteQuery('foo', 0, integerTransformer); // Ref<number>
81+
```
82+
* `floatTransformer`
83+
```js
84+
const foo = useRouteQuery('foo', 0, floatTransformer); // Ref<number>
85+
```
86+
* `booleanTransformer`
87+
```js
88+
const foo = useRouteQuery('foo', false, booleanTransformer); // Ref<boolean>
89+
```
90+
* `enumTransformer` - stores the enum key in the query and maps it back to the enum value
91+
```ts
92+
enum Foo {
93+
BAR,
94+
BAZ
95+
}
96+
97+
const foo = useRouteQuery('foo', Foo.Bar, enumTransformer); // Ref<Foo>
98+
99+
foo.value = Foo.BAZ; // Results in 'foo=BAZ' in the query
100+
```

package.json

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "vue-use-route-query",
3+
"version": "0.0.1",
4+
"author": "Kirill Romanov",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/Djaler/vue-use-route-query"
9+
},
10+
"keywords": [
11+
"vue",
12+
"router",
13+
"vue-router",
14+
"query",
15+
"composition-api",
16+
"vue-composition-api"
17+
],
18+
"scripts": {
19+
"preinstall": "npx only-allow pnpm",
20+
"lint": "eslint .",
21+
"lint:fix": "npm run lint -- --fix",
22+
"test": "vitest run",
23+
"test:watch": "vitest watch",
24+
"test:coverage": "vitest run --coverage",
25+
"check-es6": "es-check es2017 dist/index.js",
26+
"check-treeshake": "agadoo dist/index.mjs",
27+
"build": "vite build",
28+
"postbuild": "npm run check-es6 && npm run check-treeshake",
29+
"prerelease": "npm run lint && npm run test && npm run build",
30+
"release": "standard-version --preset @djaler/standard",
31+
"release:github": "conventional-github-releaser --preset @djaler/standard",
32+
"publish": "clean-publish"
33+
},
34+
"files": [
35+
"dist"
36+
],
37+
"main": "dist/index.js",
38+
"module": "dist/index.mjs",
39+
"types": "dist/index.d.ts",
40+
"sideEffects": false,
41+
"packageManager": "[email protected]",
42+
"dependencies": {
43+
"async-queue-chain": "^1.0.1"
44+
},
45+
"peerDependencies": {
46+
"@vue/composition-api": "^1.1.0",
47+
"vue": "^2.6.10",
48+
"vue-router": "^3.0.0"
49+
},
50+
"devDependencies": {
51+
"@djaler/conventional-changelog-standard": "1.2.0",
52+
"@djaler/eslint-config-typescript": "0.0.7",
53+
"@vue/composition-api": "1.4.9",
54+
"@vue/test-utils": "1.3.0",
55+
"agadoo": "2.0.0",
56+
"c8": "7.11.0",
57+
"clean-publish": "4.0.0",
58+
"conventional-github-releaser": "3.1.5",
59+
"es-check": "6.2.1",
60+
"eslint": "7.32.0",
61+
"eslint-import-resolver-typescript": "2.7.1",
62+
"jsdom": "^19.0.0",
63+
"nano-staged": "0.6.0",
64+
"simple-git-hooks": "2.7.0",
65+
"simple-promise-mock": "^1.0.0",
66+
"standard-version": "9.3.2",
67+
"typescript": "4.6.3",
68+
"vite": "2.9.1",
69+
"vite-plugin-dts": "1.0.5",
70+
"vitest": "0.9.3",
71+
"vue": "2.6.14",
72+
"vue-router": "3.1.3",
73+
"vue-template-compiler": "2.6.14"
74+
},
75+
"simple-git-hooks": {
76+
"pre-commit": "./node_modules/.bin/simple-git-hooks && ./node_modules/.bin/nano-staged"
77+
},
78+
"nano-staged": {
79+
"*.{js,ts}": "eslint --fix"
80+
}
81+
}

0 commit comments

Comments
 (0)