Skip to content

Commit

Permalink
feat: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Djaler committed Apr 13, 2022
1 parent d533901 commit 059bdb5
Show file tree
Hide file tree
Showing 25 changed files with 5,876 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/coverage/
/dist/
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
root: true,
extends: ['@djaler/typescript'],
parserOptions: {
project: './tsconfig.lint.json',
},
settings: {
'import/resolver': {
typescript: {},
},
},
rules: {
'import/no-extraneous-dependencies': ['error', {
devDependencies: [
'src/**/*.spec.ts',
'tests/**/*.ts',
'vite.config.js',
],
}],

'no-void': 'off',
},
};
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js text eol=lf
*.ts text eol=lf
73 changes: 73 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Checks

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16.9
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- name: Install dependencies
run: corepack pnpm install
- name: Run build
run: npm run build

lint:
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16.9
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- name: Install dependencies
run: corepack pnpm install
- name: Run linter
uses: reviewdog/action-eslint@v1
with:
reporter: github-check

test:
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16.9
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- name: Install dependencies
run: corepack pnpm install
- name: Run tests
run: npm run test
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16.9
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-
- name: Install dependencies
run: corepack pnpm install
- uses: filipstefansson/set-npm-token-action@v1
with:
token: ${{ secrets.NPM_TOKEN }}
- name: Build package
run: npm run build
- name: Publish package
run: npm run publish
- name: Create github release
run: npm run release:github
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
coverage/
dist/
node_modules/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-pre-post-scripts=true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Kirill Romanov

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.
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
[![npm](https://img.shields.io/npm/v/vue-use-route-query?style=for-the-badge)](https://www.npmjs.com/package/vue-use-route-query)
[![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)

# Vue Use Route Query

> A tiny Vue composable function to create a ref synced with vue router query.
## Install

```sh
npm install --save vue-use-route-query
```

or

```sh
yarn add vue-use-route-query
```

or

```sh
pnpm install vue-use-route-query
```

## Usage

Simple usage with a string parameter without any transformations

```ts
import { defineComponent } from '@vue/composition-api'
import { useRouteQuery } from 'vue-use-route-query'

export default defineComponent({
setup() {
const foo = useRouteQuery('foo', ''); // Ref<string>
const bar = useRouteQuery('bar', null); // Ref<string | null>

return {
foo,
bar,
}
}
})
```

More complex usage with a transformer function

```ts
import { defineComponent } from '@vue/composition-api'
import { useRouteQuery, RouteQueryTransformer } from 'vue-use-route-query'

export default defineComponent({
setup() {
// This transformer will reverse the string because why not
const reverseTransformer: RouteQueryTransformer<string> = {
fromQuery(query) {
return query.split('').reverse().join('');
},
toQuery(value) {
return value?.split('').reverse().join('');
}
}

const foo = useRouteQuery('foo', '', reverseTransformer);

foo.value = 'bar'; // Results in 'foo=rab' in the query

return {
foo,
}
}
})
```

A several transformers provided by the library out of the box:

* `integerTransformer`
```js
const foo = useRouteQuery('foo', 0, integerTransformer); // Ref<number>
```
* `floatTransformer`
```js
const foo = useRouteQuery('foo', 0, floatTransformer); // Ref<number>
```
* `booleanTransformer`
```js
const foo = useRouteQuery('foo', false, booleanTransformer); // Ref<boolean>
```
* `enumTransformer` - stores the enum key in the query and maps it back to the enum value
```ts
enum Foo {
BAR,
BAZ
}
const foo = useRouteQuery('foo', Foo.Bar, enumTransformer); // Ref<Foo>
foo.value = Foo.BAZ; // Results in 'foo=BAZ' in the query
```
81 changes: 81 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "vue-use-route-query",
"version": "0.0.1",
"author": "Kirill Romanov",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Djaler/vue-use-route-query"
},
"keywords": [
"vue",
"router",
"vue-router",
"query",
"composition-api",
"vue-composition-api"
],
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"test": "vitest run",
"test:watch": "vitest watch",
"test:coverage": "vitest run --coverage",
"check-es6": "es-check es2017 dist/index.js",
"check-treeshake": "agadoo dist/index.mjs",
"build": "vite build",
"postbuild": "npm run check-es6 && npm run check-treeshake",
"prerelease": "npm run lint && npm run test && npm run build",
"release": "standard-version --preset @djaler/standard",
"release:github": "conventional-github-releaser --preset @djaler/standard",
"publish": "clean-publish"
},
"files": [
"dist"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"sideEffects": false,
"packageManager": "pnpm@6.32.4",
"dependencies": {
"async-queue-chain": "^1.0.1"
},
"peerDependencies": {
"@vue/composition-api": "^1.1.0",
"vue": "^2.6.10",
"vue-router": "^3.0.0"
},
"devDependencies": {
"@djaler/conventional-changelog-standard": "1.2.0",
"@djaler/eslint-config-typescript": "0.0.7",
"@vue/composition-api": "1.4.9",
"@vue/test-utils": "1.3.0",
"agadoo": "2.0.0",
"c8": "7.11.0",
"clean-publish": "4.0.0",
"conventional-github-releaser": "3.1.5",
"es-check": "6.2.1",
"eslint": "7.32.0",
"eslint-import-resolver-typescript": "2.7.1",
"jsdom": "^19.0.0",
"nano-staged": "0.6.0",
"simple-git-hooks": "2.7.0",
"simple-promise-mock": "^1.0.0",
"standard-version": "9.3.2",
"typescript": "4.6.3",
"vite": "2.9.1",
"vite-plugin-dts": "1.0.5",
"vitest": "0.9.3",
"vue": "2.6.14",
"vue-router": "3.1.3",
"vue-template-compiler": "2.6.14"
},
"simple-git-hooks": {
"pre-commit": "./node_modules/.bin/simple-git-hooks && ./node_modules/.bin/nano-staged"
},
"nano-staged": {
"*.{js,ts}": "eslint --fix"
}
}
Loading

0 comments on commit 059bdb5

Please sign in to comment.