Browse Source

Add node polyfill files

Ben Hsieh 7 years ago
parent
commit
019e2c2098
4 changed files with 94 additions and 0 deletions
  1. 0
    0
      src/node-polyfill/events.js
  2. 19
    0
      src/node-polyfill/fs.js
  3. 52
    0
      src/node-polyfill/path.js
  4. 23
    0
      src/node-polyfill/util.js

+ 0
- 0
src/node-polyfill/events.js View File


+ 19
- 0
src/node-polyfill/fs.js View File

@@ -0,0 +1,19 @@
1
+// Copyright 2016 wkh237@github. All rights reserved.
2
+// Use of this source code is governed by a MIT-style license that can be
3
+// found in the LICENSE file.
4
+// @flow
5
+
6
+import {
7
+  NativeModules,
8
+  DeviceEventEmitter,
9
+  Platform,
10
+  NativeAppEventEmitter,
11
+} from 'react-native'
12
+
13
+const RNFB = NativeModules.RNFetchBlob
14
+
15
+export default class FS {
16
+
17
+  static
18
+
19
+}

+ 52
- 0
src/node-polyfill/path.js View File

@@ -0,0 +1,52 @@
1
+// Copyright 2016 wkh237@github. All rights reserved.
2
+// Use of this source code is governed by a MIT-style license that can be
3
+// found in the LICENSE file.
4
+// @flow
5
+import Log from '../utils/log'
6
+import path from 'path-parse'
7
+const log = new Log('node-path')
8
+
9
+log.level(3)
10
+log.info('node-path polyfill loaded')
11
+
12
+const sep = '/'
13
+
14
+function basename(str:string):string {
15
+  return path.parse(str).base
16
+}
17
+
18
+function dirname(str:string):string {
19
+  return path.parse(str).dir
20
+}
21
+
22
+function extname(str:string):string {
23
+  return path.parse(str).ext
24
+}
25
+
26
+function format(args:any):string {
27
+  // TODO :
28
+}
29
+
30
+function isAbsolute(str:string):boolean {
31
+  // TODO :
32
+  return true
33
+}
34
+
35
+function join(arr:Array):string {
36
+  // TODO : error handling and type checking
37
+  return arr.join('')
38
+}
39
+
40
+function normalize(str:string):string {
41
+  // TODO
42
+  return str
43
+}
44
+
45
+// since nodejs modules uses es5 export by default, we should use es5 export here
46
+export {
47
+  extname,
48
+  dirname,
49
+  basename,
50
+  // TODOs
51
+  normalize,
52
+}

+ 23
- 0
src/node-polyfill/util.js View File

@@ -0,0 +1,23 @@
1
+// Copyright 2016 wkh237@github. All rights reserved.
2
+// Use of this source code is governed by a MIT-style license that can be
3
+// found in the LICENSE file.
4
+// @flow
5
+import Log from '../utils/log'
6
+const log = new Log('node-util')
7
+
8
+log.level(3)
9
+log.info('node-util polyfill loaded')
10
+
11
+function inherits(ctor, superCtor):any {
12
+  log.verbose('inherits', superCtor, superCtor)
13
+  if(superCtor) {
14
+    ctor.prototype = superCtor.prototype
15
+    ctor.super_ = superCtor
16
+  }
17
+  return ctor
18
+}
19
+
20
+// since nodejs modules uses es5 export by default, we should use es5 export here
21
+export {
22
+  inherits
23
+}