Browse Source

Add URI util

Ben Hsieh 8 years ago
parent
commit
8988cc8c7e
1 changed files with 28 additions and 0 deletions
  1. 28
    0
      src/utils/uri.js

+ 28
- 0
src/utils/uri.js View File

@@ -0,0 +1,28 @@
1
+export default {
2
+
3
+  isFileURI : (uri:string):boolean => {
4
+    if(typeof uri !== 'string')
5
+      return false
6
+    return /^RNFetchBlob-file\:\/\//.test(uri)
7
+  },
8
+
9
+  isJSONStreamURI : (uri:string):boolean => {
10
+    if(typeof uri !== 'string')
11
+      return false
12
+    return /^JSONStream\:\/\//.test(uri)
13
+  },
14
+
15
+  removeURIScheme : (uri:string, iterations:number):string => {
16
+    iterations = iterations || 1
17
+    let result = uri
18
+    for(let i=0;i<iterations;i++) {
19
+      result = String(result).replace(/^[^\:]+\:\/\//, '')
20
+    }
21
+    return String(result)
22
+  },
23
+
24
+  unwrapFileURI : (uri:string):string => {
25
+    return String(uri).replace(/^RNFetchBlob-file\:\/\//, '')
26
+  }
27
+
28
+}