vue-useurl
Advanced tools
Comparing version 1.0.17 to 1.0.18
{ | ||
"name": "vue-useurl", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"description": "Url Builder Hook for Vue.js Composition API", | ||
@@ -29,2 +29,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"typedoc": "^0.22.15", | ||
"vue-demi": "latest" | ||
@@ -31,0 +32,0 @@ }, |
132
README.md
<img src="https://raw.githubusercontent.com/rainxh11/vue-useurl/master/assets/logo.svg" width="300"> | ||
# vue-useurl ( Url Builder Vue Hook ) | ||
# vue-useurl ( Reactive Url Builder Vue Hook for Vue 2 & Vue 3 ) | ||
[![NPM version](https://img.shields.io/npm/v/vue-useurl.svg)](https://www.npmjs.com/package/vue-useurl) | ||
A library for building URL using ***(Query Parameters, Path Variables, Hash)*,** while being reactive and ready to use as Vue Composition API Hook | ||
A library for building URL using ***(Query Parameters, Path Variables, Hash, Path)*** while being reactive and ready to use as Vue Composition API Hook | ||
@@ -22,19 +22,19 @@ ## Installation | ||
const params = { | ||
search: 'ahmed', | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: ['Cancelled', 'OnGoing'] | ||
search: 'ahmed', | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: ['Cancelled', 'OnGoing'] | ||
} | ||
const { url, queryParams, pathVariables, hash, path, disableCSV } = useUrl({ | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
...params | ||
}, | ||
hash: 'someHash', | ||
disableCSV: false | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
...params | ||
}, | ||
hash: 'someHash', | ||
disableCSV: false | ||
}, | ||
@@ -51,14 +51,14 @@ 'http://api.com') | ||
path: '/path/path1', // URL Path | ||
pathVariables: { | ||
id: 451 | ||
}, // Path variables e.g: /:id/ | ||
queryParams: { | ||
limit:10, | ||
sortBy: 'property', | ||
page: 1 | ||
}, // Query parameters | ||
hash: 'someHash', // Hash | ||
disableCSV: false | ||
// Enabled: param=1¶m=2¶m=3 | ||
// Disabled: param=1,2,3 | ||
pathVariables: { | ||
id: 451 | ||
}, // Path variables e.g: /:id/ | ||
queryParams: { | ||
limit:10, | ||
sortBy: 'property', | ||
page: 1 | ||
}, // Query parameters | ||
hash: 'someHash', // Hash | ||
disableCSV: false | ||
// Enabled: param=1¶m=2¶m=3 | ||
// Disabled: param=1,2,3 | ||
} | ||
@@ -70,3 +70,3 @@ ``` | ||
```ts | ||
buildUrl('http://example.com', { | ||
buildUrl('http://api.com', { | ||
path: 'about', | ||
@@ -97,24 +97,23 @@ hash: 'hash', | ||
const { url, queryParams, pathVariables, hash, path, disableCSV } = useUrl({ | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
search: 'ahmed', | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: ['Cancelled', 'OnGoing'] | ||
}, | ||
hash: 'hashtag', | ||
disableCSV: false | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
search: 'ahmed', | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: ['Cancelled', 'OnGoing'] | ||
}, | ||
hash: 'hashtag', | ||
disableCSV: false | ||
}, | ||
'http://api.com') | ||
const { isFetching, error, data } = useFetch<Contact[]>( | ||
const { isFetching, error, data } = useFetch( | ||
url, | ||
{ initialData: { results: [] }, refetch: true} | ||
) | ||
.get() | ||
.json() | ||
{ initialData: { results: [] }, refetch: true}) | ||
.get() | ||
.json() | ||
``` | ||
@@ -134,25 +133,23 @@ | ||
const { url, queryParams, pathVariables, hash, path, disableCSV } = useUrl({ | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
search: useDebounce(search, 500), // | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: useDebounce(filters, 3500) // then pass their reactive backpressure objects instead | ||
}, | ||
hash: 'hashtag', | ||
disableCSV: false | ||
path: '/api/v1/users/:id/search', | ||
pathVariables: { | ||
id: 451 | ||
}, | ||
queryParams: { | ||
search: useDebounce(search, 500), // | ||
limit: 50, | ||
page: 12, | ||
sort: 'CreatedOn', | ||
types: useDebounce(filters, 3500) // then pass their reactive backpressure objects instead | ||
}, | ||
hash: 'hashtag', | ||
disableCSV: false | ||
}, | ||
'http://api.com') | ||
const { isFetching, error, data } = useFetch<Contact[]>( | ||
const { isFetching, error, data } = useFetch( | ||
url, | ||
{ initialData: { results: [] }, refetch: true} | ||
) | ||
.get() | ||
.json() | ||
} | ||
{ initialData: { results: [] }, refetch: true}) | ||
.get() | ||
.json() | ||
@@ -173,5 +170,4 @@ return { | ||
## License | ||
This is licensed under an MIT License. (LICENSE) | ||
This is licensed under an MIT License. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useUrl = exports.UrlBuilder = exports.BuilderResult = void 0; | ||
exports.createUseUrlInstance = exports.useUrl = exports.UrlBuilder = exports.BuilderResult = void 0; | ||
const vue_demi_1 = require("vue-demi"); | ||
@@ -65,2 +65,15 @@ (0, vue_demi_1.install)(); | ||
exports.UrlBuilder = UrlBuilder; | ||
/** | ||
* Create a reactive url | ||
* @param {IUrlOptions | any} options Builder Options | ||
* @param {string} baseUrl Base URL | ||
* @returns {IBuilderResult} `{ | ||
* url, | ||
* queryParams, | ||
* pathVariables, | ||
* hash, | ||
* path, | ||
* disableCSV | ||
* }` | ||
*/ | ||
const useUrl = (options, baseUrl) => { | ||
@@ -82,1 +95,10 @@ const builderResult = new BuilderResult(options.path, options.pathVariables, options.queryParams, options.hash, options.disableCSV); | ||
exports.useUrl = useUrl; | ||
/** | ||
* Create a new instance of useUrl() | ||
* @param {string} baseUrl Base URL | ||
* @returns {function} Instance function | ||
*/ | ||
const createUseUrlInstance = (baseUrl = '') => { | ||
return useUrl(baseUrl); | ||
}; | ||
exports.createUseUrlInstance = createUseUrlInstance; |
@@ -95,3 +95,16 @@ import { ref, reactive, computed, Ref, UnwrapRef, ComputedRef, install } from 'vue-demi'; | ||
export const useUrl = (options:IUrlOptions|any, baseUrl?:string):IBuilderResult => { | ||
/** | ||
* Create a reactive url | ||
* @param {IUrlOptions | any} options Builder Options | ||
* @param {string} baseUrl Base URL | ||
* @returns {IBuilderResult} `{ | ||
* url, | ||
* queryParams, | ||
* pathVariables, | ||
* hash, | ||
* path, | ||
* disableCSV | ||
* }` | ||
*/ | ||
const useUrl = (options:IUrlOptions|any, baseUrl?:string):IBuilderResult => { | ||
const builderResult = new BuilderResult( | ||
@@ -119,2 +132,14 @@ options.path, | ||
return builderResult | ||
} | ||
} | ||
/** | ||
* Create a new instance of useUrl() | ||
* @param {string} baseUrl Base URL | ||
* @returns {function} Instance function | ||
*/ | ||
const createUseUrlInstance = (baseUrl:string = '') => { | ||
return useUrl(baseUrl) | ||
} | ||
export { useUrl, createUseUrlInstance } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25524
10
325
4
168
+ Addedtypedoc@^0.22.15
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedjsonc-parser@3.3.1(transitive)
+ Addedlunr@2.3.9(transitive)
+ Addedmarked@4.3.0(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedshiki@0.10.1(transitive)
+ Addedtypedoc@0.22.18(transitive)
+ Addedtypescript@4.7.4(transitive)
+ Addedvscode-oniguruma@1.7.0(transitive)
+ Addedvscode-textmate@5.2.0(transitive)
+ Addedwrappy@1.0.2(transitive)