Skip to content

Commit

Permalink
chore: add isHttps func
Browse files Browse the repository at this point in the history
  • Loading branch information
vtrbo committed Mar 27, 2023
1 parent 4f83d97 commit 4b9451e
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default [
{ text: 'isBoolean', link: '/method/fn/isBoolean' },
{ text: 'isDate', link: '/method/fn/isDate' },
{ text: 'isFunction', link: '/method/fn/isFunction' },
{ text: 'isHttps', link: '/method/fn/isHttps' },
{ text: 'isMap', link: '/method/fn/isMap' },
{ text: 'isNull', link: '/method/fn/isNull' },
{ text: 'isNumber', link: '/method/fn/isNumber' },
Expand Down
24 changes: 24 additions & 0 deletions docs/method/fn/isHttps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# IsHttps

## Description
是否是https协议

## Run Online

<RunCode :language="ts">

```ts
console.log(isHttps())
```

</RunCode>

## Options

<div class="utils-table">

| 属性名 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |


</div>
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"devDependencies": {
"vitepress": "1.0.0-alpha.58",
"vitepress-plugin-runcode": "^0.3.1"
"vitepress-plugin-runcode": "^0.3.4"
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
"docs:serve": "nr -C docs serve"
},
"devDependencies": {
"@types/jsdom": "^21.1.1",
"@types/node": "^18.15.3",
"@vtrbo/eslint-config": "^0.2.2",
"@vtrbo/ni": "^0.1.0",
"bumpp": "^9.0.0",
"eslint": "^8.36.0",
"esno": "^0.16.3",
"fast-glob": "^3.2.12",
"jsdom": "^21.1.1",
"pnpm": "^7.29.1",
"tsup": "^6.6.3",
"typescript": "^4.9.5",
Expand Down
7 changes: 7 additions & 0 deletions packages/fn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import {
isFunction,
} from './isFunction'

import {
isHttps,
} from './isHttps'

import {
isMap,
} from './isMap'
Expand Down Expand Up @@ -115,6 +119,7 @@ export const resolveFnUtils = (aliasPrefix?: string): Record<string, [string, st
['isBoolean', aliasPrefix ? `${aliasPrefix}IsBoolean` : 'isBoolean'],
['isDate', aliasPrefix ? `${aliasPrefix}IsDate` : 'isDate'],
['isFunction', aliasPrefix ? `${aliasPrefix}IsFunction` : 'isFunction'],
['isHttps', aliasPrefix ? `${aliasPrefix}IsHttps` : 'isHttps'],
['isMap', aliasPrefix ? `${aliasPrefix}IsMap` : 'isMap'],
['isNull', aliasPrefix ? `${aliasPrefix}IsNull` : 'isNull'],
['isNumber', aliasPrefix ? `${aliasPrefix}IsNumber` : 'isNumber'],
Expand All @@ -141,6 +146,7 @@ export {
isBoolean,
isDate,
isFunction,
isHttps,
isMap,
isNull,
isNumber,
Expand All @@ -165,6 +171,7 @@ export default {
isBoolean,
isDate,
isFunction,
isHttps,
isMap,
isNull,
isNumber,
Expand Down
3 changes: 3 additions & 0 deletions packages/fn/isHttps.exam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { isHttps } from "./isHttps";

console.log(isHttps())
19 changes: 19 additions & 0 deletions packages/fn/isHttps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @desc 是否是https协议
*
* @func isHttps
* @returns { boolean } 校验结果
*/
export function isHttps(): boolean {
const protocol = window.location.protocol
if (protocol === 'https:') {
return true
}
else if (protocol === 'http:') {
return false
}
else {
const baseUrl = window.location.origin
return baseUrl.startsWith('https:')
}
}
4 changes: 4 additions & 0 deletions packages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ it('resolveUtils', () => {
"isFunction",
"utilIsFunction",
],
[
"isHttps",
"utilIsHttps",
],
[
"isMap",
"utilIsMap",
Expand Down
Loading

0 comments on commit 4b9451e

Please sign in to comment.