Skip to content

Commit

Permalink
Feat: add changeURL ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
pandaoh committed Dec 29, 2023
1 parent e12bd33 commit e58a913
Show file tree
Hide file tree
Showing 299 changed files with 1,718 additions and 861 deletions.
2 changes: 1 addition & 1 deletion dist/Array/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion dist/Request/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export declare function qsParse(url?: string, key?: string): any;
* getBaseURL('https://test.com/index?name=leo&org=biugle#test'); /// 'https://test.com/index'
* getBaseURL(''); /// ''
* getBaseURL(); /// 当前页面 BaseURL
* getBaseURL('https://test.com/#/test?name=leo&org=biugle', true); /// 'https://test.com/#/test'
* getBaseURL(null); /// 相当于 window.location.origin
* @param url 地址/链接
* @param hashRoute 是否为 hash 路由,默认为 false 。
* @returns
*/
export declare function getBaseURL(url?: string): string;
export declare function getBaseURL(url?: string, hashRoute?: boolean): string;
/**
* 获取 url 查询参数字符串
* @example
Expand All @@ -44,6 +47,19 @@ export declare function getBaseURL(url?: string): string;
* @returns
*/
export declare function getQueryString(url?: string): any;
/**
* 改变 URL 地址而不刷新页面,并且支持保留或替换历史记录
* @example
* 假如当前地址为:https://test.com/user
* changeURL('leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('./leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('/users'); /// url 变为 'https://test.com/users'
* changeURL('https://test.com/test'); /// url 变为 'https://test.com/test' (若域名不同,会报错中断。)
* changeURL('/users', false); /// url 变为 'https://test.com/users' (不覆盖历史记录,返回时会再显示 'https://test.com/user',而上面的例子返回时是直接显示 'https://test.com/user' 的上一条。)
* @param url URL 地址
* @param replaceHistory 是否替换历史记录,默认为 true 。
*/
export declare function changeURL(url: string, replaceHistory?: boolean): void;
/**
* 获取查询地址/链接中的参数对象
* @example
Expand Down
2 changes: 1 addition & 1 deletion dist/Request/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/Tools/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export declare function onResize(foo: any): any;
* 获取简单的浏览器指纹
* @example
* getFingerprint(); /// md5 加密后的指纹
* getFingerprint('test'); /// md5 加密后的指纹
* getFingerprint('test'); /// md5 加密后的指纹-建议增加使用者标识,避免指纹冲突。
* @param extraString 额外的字符串,可以说用户名等。
* @returns
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

38 changes: 35 additions & 3 deletions dist/index.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
* @Author: HxB
* @Date: 2022-04-26 11:52:01
* @LastEditors: DoubleAm
* @LastEditTime: 2023-08-24 14:41:03
* @LastEditTime: 2023-12-15 18:30:28
* @Description: 数组常用函数
* @FilePath: \js-xxx\src\Array\index.ts
*/
Expand Down Expand Up @@ -9474,7 +9474,7 @@
* 获取简单的浏览器指纹
* @example
* getFingerprint(); /// md5 加密后的指纹
* getFingerprint('test'); /// md5 加密后的指纹
* getFingerprint('test'); /// md5 加密后的指纹-建议增加使用者标识,避免指纹冲突。
* @param extraString 额外的字符串,可以说用户名等。
* @returns
*/
Expand Down Expand Up @@ -12894,11 +12894,21 @@
* getBaseURL('https://test.com/index?name=leo&org=biugle#test'); /// 'https://test.com/index'
* getBaseURL(''); /// ''
* getBaseURL(); /// 当前页面 BaseURL
* getBaseURL('https://test.com/#/test?name=leo&org=biugle', true); /// 'https://test.com/#/test'
* getBaseURL(null); /// 相当于 window.location.origin
* @param url 地址/链接
* @param hashRoute 是否为 hash 路由,默认为 false 。
* @returns
*/
function getBaseURL(url) {
function getBaseURL(url, hashRoute) {
if (hashRoute === void 0) { hashRoute = false; }
if (url === null) {
return window.location.origin;
}
url = url !== null && url !== void 0 ? url : window.location.href;
if (hashRoute) {
return url.split('?')[0];
}
return url.replace(/[?#].*$/, '');
}
/**
Expand All @@ -12914,6 +12924,27 @@
var _a, _b, _c, _d, _e;
return toBool(url) ? (_d = (_c = (_b = (_a = url === null || url === void 0 ? void 0 : url.split('?')) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split('#')) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : '' : (_e = window.location.search) === null || _e === void 0 ? void 0 : _e.replace('?', '');
}
/**
* 改变 URL 地址而不刷新页面,并且支持保留或替换历史记录
* @example
* 假如当前地址为:https://test.com/user
* changeURL('leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('./leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('/users'); /// url 变为 'https://test.com/users'
* changeURL('https://test.com/test'); /// url 变为 'https://test.com/test' (若域名不同,会报错中断。)
* changeURL('/users', false); /// url 变为 'https://test.com/users' (不覆盖历史记录,返回时会再显示 'https://test.com/user',而上面的例子返回时是直接显示 'https://test.com/user' 的上一条。)
* @param url URL 地址
* @param replaceHistory 是否替换历史记录,默认为 true 。
*/
function changeURL(url, replaceHistory) {
if (replaceHistory === void 0) { replaceHistory = true; }
if (replaceHistory) {
window.history.replaceState({}, '', url);
}
else {
window.history.pushState({}, '', url);
}
}
/**
* 获取查询地址/链接中的参数对象
* @example
Expand Down Expand Up @@ -14184,6 +14215,7 @@
exports.calcDate = calcDate;
exports.calcFontSize = calcFontSize;
exports.catchPromise = catchPromise;
exports.changeURL = changeURL;
exports.checkFileExt = checkFileExt;
exports.checkIdCard = checkIdCard;
exports.checkPassWordLevel = checkPassWordLevel;
Expand Down
46 changes: 40 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
js-xxx

# js-xxx - v2.0.9
# js-xxx - v2.0.10

## Table of contents

Expand Down Expand Up @@ -59,6 +59,7 @@ js-xxx
- [calcDate](README.md#calcdate)
- [calcFontSize](README.md#calcfontsize)
- [catchPromise](README.md#catchpromise)
- [changeURL](README.md#changeurl)
- [checkFileExt](README.md#checkfileext)
- [checkIdCard](README.md#checkidcard)
- [checkPassWordLevel](README.md#checkpasswordlevel)
Expand Down Expand Up @@ -1227,6 +1228,36 @@ new catchPromise(resolve, reject, rejectHandler); /// Promise
___
### changeURL
▸ **changeURL**(`url`, `replaceHistory?`): `void`
改变 URL 地址而不刷新页面,并且支持保留或替换历史记录
**`Example`**
```ts
假如当前地址为:https://test.com/user
changeURL('leo'); /// url 变为 'https://test.com/user/leo'
changeURL('./leo'); /// url 变为 'https://test.com/user/leo'
changeURL('/users'); /// url 变为 'https://test.com/users'
changeURL('https://test.com/test'); /// url 变为 'https://test.com/test' (若域名不同,会报错中断。)
changeURL('/users', false); /// url 变为 'https://test.com/users' (不覆盖历史记录,返回时会再显示 'https://test.com/user',而上面的例子返回时是直接显示 'https://test.com/user' 的上一条。)
```
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `url` | `string` | `undefined` | URL 地址 |
| `replaceHistory` | `boolean` | `true` | 是否替换历史记录,默认为 true 。 |
#### Returns
`void`
___
### checkFileExt
▸ **checkFileExt**(`arr`, `value`): `boolean`
Expand Down Expand Up @@ -2327,7 +2358,7 @@ ___
### getBaseURL
▸ **getBaseURL**(`url?`): `string`
▸ **getBaseURL**(`url?`, `hashRoute?`): `string`
获取不带任何参数或片段标识符的当前 URL
Expand All @@ -2337,13 +2368,16 @@ ___
getBaseURL('https://test.com/index?name=leo&org=biugle#test'); /// 'https://test.com/index'
getBaseURL(''); /// ''
getBaseURL(); /// 当前页面 BaseURL
getBaseURL('https://test.com/#/test?name=leo&org=biugle', true); /// 'https://test.com/#/test'
getBaseURL(null); /// 相当于 window.location.origin
```
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `url?` | `string` | 地址/链接 |
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `url?` | `string` | `undefined` | 地址/链接 |
| `hashRoute` | `boolean` | `false` | 是否为 hash 路由,默认为 false 。 |
#### Returns
Expand Down Expand Up @@ -2626,7 +2660,7 @@ ___
```ts
getFingerprint(); /// md5 加密后的指纹
getFingerprint('test'); /// md5 加密后的指纹
getFingerprint('test'); /// md5 加密后的指纹-建议增加使用者标识,避免指纹冲突。
```
#### Parameters
Expand Down
2 changes: 1 addition & 1 deletion docs/enums/HttpMethod.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[js-xxx - v2.0.9](../README.md) / HttpMethod
[js-xxx - v2.0.10](../README.md) / HttpMethod

# Enumeration: HttpMethod

Expand Down
2 changes: 1 addition & 1 deletion es/Array/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion es/Request/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export declare function qsParse(url?: string, key?: string): any;
* getBaseURL('https://test.com/index?name=leo&org=biugle#test'); /// 'https://test.com/index'
* getBaseURL(''); /// ''
* getBaseURL(); /// 当前页面 BaseURL
* getBaseURL('https://test.com/#/test?name=leo&org=biugle', true); /// 'https://test.com/#/test'
* getBaseURL(null); /// 相当于 window.location.origin
* @param url 地址/链接
* @param hashRoute 是否为 hash 路由,默认为 false 。
* @returns
*/
export declare function getBaseURL(url?: string): string;
export declare function getBaseURL(url?: string, hashRoute?: boolean): string;
/**
* 获取 url 查询参数字符串
* @example
Expand All @@ -44,6 +47,19 @@ export declare function getBaseURL(url?: string): string;
* @returns
*/
export declare function getQueryString(url?: string): any;
/**
* 改变 URL 地址而不刷新页面,并且支持保留或替换历史记录
* @example
* 假如当前地址为:https://test.com/user
* changeURL('leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('./leo'); /// url 变为 'https://test.com/user/leo'
* changeURL('/users'); /// url 变为 'https://test.com/users'
* changeURL('https://test.com/test'); /// url 变为 'https://test.com/test' (若域名不同,会报错中断。)
* changeURL('/users', false); /// url 变为 'https://test.com/users' (不覆盖历史记录,返回时会再显示 'https://test.com/user',而上面的例子返回时是直接显示 'https://test.com/user' 的上一条。)
* @param url URL 地址
* @param replaceHistory 是否替换历史记录,默认为 true 。
*/
export declare function changeURL(url: string, replaceHistory?: boolean): void;
/**
* 获取查询地址/链接中的参数对象
* @example
Expand Down
Loading

0 comments on commit e58a913

Please sign in to comment.