Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 019e2c2

Browse files
committed
Add node polyfill files
1 parent 32e2db0 commit 019e2c2

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

src/node-polyfill/events.js

Whitespace-only changes.

src/node-polyfill/fs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/node-polyfill/path.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/node-polyfill/util.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

0 commit comments

Comments
 (0)