Skip to content

Commit

Permalink
feat: new function - isAlipay
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatAuk committed Mar 19, 2024
1 parent 9915cf4 commit 7644acb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pnpm add @utopia-utils/dom
* canUseDom: 判断是否可以使用 `document``window` 对象,判断是否是 ssr 场景。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/canUseDom.ts)
* domContains: 原生 `Node.contains()` 的兼容写法 。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/domContains.ts)
* updateCSS: 注入 css 样式(通过动态插入 style 标签)。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/dyncmicCSS.ts)
* isAlipay: 判断是否是支付宝浏览器。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/isAlipay.ts)
* isAndroid: 判断是否是 Android 系统。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/isAndroid.ts)
* isIOS: 判断是否是 IOS 系统。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/isIOS.ts)
* isWeixin: 判断是否是微信浏览器。[source](https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/isWeixin.ts)
Expand Down
1 change: 1 addition & 0 deletions packages/dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './panzoom'
export * from './canUseDom'
export * from './domContains'
export * from './dynamicCSS'
export * from './isAlipay'
export * from './isAndroid'
export * from './isIOS'
export * from './isMobile'
Expand Down
14 changes: 14 additions & 0 deletions packages/dom/src/isAlipay.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isAlipay } from './isAlipay'

describe('isAlipay', () => {
afterEach(() => {
vi.resetAllMocks()
})
it('should return false if ua does not contain Alipay', () => {
expect(isAlipay()).toBe(false)
})
it('should return true if ua contains Alipay', () => {
vi.spyOn(navigator, 'userAgent', 'get').mockReturnValueOnce('Alipay')
expect(isAlipay()).toBe(true)
})
})
9 changes: 9 additions & 0 deletions packages/dom/src/isAlipay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Check if the current environment is Alipay. (支付宝)
* @returns A boolean value.
* @linkcode https://github.com/GreatAuk/utopia-utils/blob/main/packages/dom/src/isAlipay.ts
*/
export function isAlipay(): boolean {
const ua = navigator.userAgent.toLowerCase()
return /Alipay/i.test(ua)
}
2 changes: 1 addition & 1 deletion packages/share/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* @returns The type of the value. such as Object, Array, Map, Set, Date, RegExp, String, Number, Boolean, Symbol, Function, Promise, Undefined, Null, NaN, Infinity, -Infinity, Error, Arguments, Element, Window, Document, DocumentFragment, Text, Comment, DocumentType, ProcessingInstruction, CDATASection, XMLDocument, XMLSerializer, XPathEvaluator, XPathExpression, XPathResult, Attr, CharacterData, NamedNodeMap, Node, NodeList, HTMLCollection, StyleSheet, CSSRule, CSSRuleList, CSSStyleDeclaration, CSSValue, CSSValueList, ClientRect, ClientRectList, DOMRectList, DOMStringList, DOMTokenList, MediaList, StyleSheetList, TextMetrics, TimeRanges, BarProp, Location, Navigator, Performance, Screen, Crypto, CryptoKey, DOMException, DOMImplementation, Event, MessageEvent, CloseEvent, ErrorEvent, EventSource, HashChangeEvent, PopStateEvent, ProgressEvent, CustomEvent, CompositionEvent, FocusEvent, InputEvent, KeyboardEvent, MouseEvent, PointerEvent, TouchEvent, WheelEvent, UIEvent, AnimationEvent, TransitionEvent, Blob, File, FileList, FileReader, FormData, URLSearchParams, ArrayBuffer, ArrayBufferView, DataView, Float32Array, Float64Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Uint8ClampedArray, SharedArrayBuffer, Atomics, JSON, Math, Reflect and so on.
* @linkcode https://github.com/GreatAuk/utopia-utils/blob/main/packages/share/src/toTypeString.ts
*/
export const toTypeString = (value: unknown): string => {
export function toTypeString(value: unknown): string {
return Object.prototype.toString.call(value).slice(8, -1)
}

0 comments on commit 7644acb

Please sign in to comment.