1 |
|
2 |
|
3 |
|
4 | export const hasProto = '__proto__' in {}
|
5 |
|
6 |
|
7 | export const inBrowser = typeof window !== 'undefined'
|
8 | export const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
|
9 | export const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase()
|
10 | export const UA = inBrowser && window.navigator.userAgent.toLowerCase()
|
11 | export const isIE = UA && /msie|trident/.test(UA)
|
12 | export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
|
13 | export const isEdge = UA && UA.indexOf('edge/') > 0
|
14 | export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android')
|
15 | export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios')
|
16 | export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
|
17 | export const isPhantomJS = UA && /phantomjs/.test(UA)
|
18 | export const isFF = UA && UA.match(/firefox\/(\d+)/)
|
19 |
|
20 |
|
21 | export const nativeWatch = ({}).watch
|
22 |
|
23 | export let supportsPassive = false
|
24 | if (inBrowser) {
|
25 | try {
|
26 | const opts = {}
|
27 | Object.defineProperty(opts, 'passive', ({
|
28 | get () {
|
29 |
|
30 | supportsPassive = true
|
31 | }
|
32 | }: Object))
|
33 | window.addEventListener('test-passive', null, opts)
|
34 | } catch (e) {}
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 | let _isServer
|
40 | export const isServerRendering = () => {
|
41 | if (_isServer === undefined) {
|
42 |
|
43 | if (!inBrowser && !inWeex && typeof global !== 'undefined') {
|
44 |
|
45 |
|
46 | _isServer = global['process'] && global['process'].env.VUE_ENV === 'server'
|
47 | } else {
|
48 | _isServer = false
|
49 | }
|
50 | }
|
51 | return _isServer
|
52 | }
|
53 |
|
54 |
|
55 | export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
|
56 |
|
57 |
|
58 | export function isNative (Ctor: any): boolean {
|
59 | return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
|
60 | }
|
61 |
|
62 | export const hasSymbol =
|
63 | typeof Symbol !== 'undefined' && isNative(Symbol) &&
|
64 | typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys)
|
65 |
|
66 | let _Set
|
67 |
|
68 | if (typeof Set !== 'undefined' && isNative(Set)) {
|
69 |
|
70 | _Set = Set
|
71 | } else {
|
72 |
|
73 | _Set = class Set implements SimpleSet {
|
74 | set: Object;
|
75 | constructor () {
|
76 | this.set = Object.create(null)
|
77 | }
|
78 | has (key: string | number) {
|
79 | return this.set[key] === true
|
80 | }
|
81 | add (key: string | number) {
|
82 | this.set[key] = true
|
83 | }
|
84 | clear () {
|
85 | this.set = Object.create(null)
|
86 | }
|
87 | }
|
88 | }
|
89 |
|
90 | export interface SimpleSet {
|
91 | has(key: string | number): boolean;
|
92 | add(key: string | number): mixed;
|
93 | clear(): void;
|
94 | }
|
95 |
|
96 | export { _Set }
|