1
- //! AlaSQL v0.3.8 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
1
+ //! AlaSQL v0.3.9 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
2
2
/*
3
3
@module alasql
4
- @version 0.3.8
4
+ @version 0.3.9
5
5
6
6
AlaSQL - JavaScript SQL database
7
7
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
@@ -137,7 +137,7 @@ var alasql = function(sql, params, cb, scope) {
137
137
Current version of alasql
138
138
@constant {string}
139
139
*/
140
- alasql.version = '0.3.8 ';
140
+ alasql.version = '0.3.9 ';
141
141
142
142
/**
143
143
Debug flag
@@ -3391,7 +3391,7 @@ utils.isMeteor = (function(){
3391
3391
Find out if code is running on a Meteor client
3392
3392
@return {boolean} True if code is running on a Meteor client
3393
3393
*/
3394
- utils.isMeteorClient = ( utils.isMeteorClient = function(){
3394
+ utils.isMeteorClient = utils.isMeteorClient = ( function(){
3395
3395
return utils.isMeteor && Meteor.isClient;
3396
3396
})();
3397
3397
@@ -3413,6 +3413,18 @@ utils.isCordova = (function(){
3413
3413
return (typeof cordova === 'object')
3414
3414
})();
3415
3415
3416
+ utils.isReactNative = (function(){
3417
+ var isReact = false;
3418
+ //*not-for-browser/*
3419
+ try{
3420
+ if(typeof require('react-native') === 'object'){
3421
+ isReact = true;
3422
+ }
3423
+ }catch(e){void 0 }
3424
+ //*/
3425
+ return isReact;
3426
+ })();
3427
+
3416
3428
utils.hasIndexedDB = (function(){
3417
3429
return !!utils.global.indexedDB;
3418
3430
})();
@@ -3479,7 +3491,15 @@ var loadFile = utils.loadFile = function(path, asy, success, error) {
3479
3491
}
3480
3492
}
3481
3493
}
3482
- //*/
3494
+ } else if(utils.isReactNative) {
3495
+ // If ReactNative
3496
+ var RNFS = require('react-native-fs');
3497
+ RNFS.readFile(path,'utf8').then(function(contents){
3498
+ success(cutbom(contents));
3499
+ }).catch(function(err){
3500
+ throw err;
3501
+ });
3502
+ //*/
3483
3503
} else if(utils.isCordova) {
3484
3504
/* If Cordova */
3485
3505
utils.global.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
@@ -3609,9 +3629,18 @@ var loadBinaryFile = utils.loadBinaryFile = function(path, asy, success, error)
3609
3629
success(arr.join(""));
3610
3630
}
3611
3631
}
3612
- //*/
3632
+ } else if(utils.isReactNative) {
3633
+ // If ReactNative
3634
+ //var RNFS = require('react-native-fs');
3635
+ var RNFetchBlob = require('react-native-fetch-blob').default
3636
+ var dirs = RNFetchBlob.fs.dirs
3637
+ //should use readStream instead if the file is large
3638
+ RNFetchBlob.fs.readFile(path, 'base64').then(function(data){
3639
+ //RNFetchBlob.base64.decode(data) //need more test on excel
3640
+ success(data);
3641
+ })
3642
+ //*/
3613
3643
} else {
3614
-
3615
3644
if(typeof path === "string") {
3616
3645
// For browser
3617
3646
var xhr = new XMLHttpRequest();
@@ -3657,7 +3686,15 @@ var removeFile = utils.removeFile = function(path,cb) {
3657
3686
cb && cb(); // jshint ignore:line
3658
3687
});
3659
3688
});
3660
- //*/
3689
+ } else if(utils.isReactNative) {
3690
+ // If ReactNative
3691
+ var RNFS = require('react-native-fs');
3692
+ RNFS.unlink(path).then(function(){
3693
+ cb && cb();
3694
+ }).catch(function(err){
3695
+ throw err;
3696
+ });
3697
+ //*/
3661
3698
} else {
3662
3699
throw new Error('You can remove files only in Node.js and Apache Cordova');
3663
3700
}
@@ -3669,13 +3706,22 @@ var deleteFile = utils.deleteFile = function(path,cb){
3669
3706
if(utils.isNode) {
3670
3707
var fs = require('fs');
3671
3708
fs.unlink(path, cb);
3709
+ } else if(utils.isReactNative) {
3710
+ // If ReactNative
3711
+ var RNFS = require('react-native-fs');
3712
+ RNFS.unlink(path).then(function(){
3713
+ cb && cb();
3714
+ }).catch(function(err){
3715
+ throw err;
3716
+ });
3672
3717
}
3673
3718
//*/
3674
3719
3675
3720
};
3676
3721
3677
3722
utils.autoExtFilename = function(filename,ext,config) {
3678
- if(typeof filename !== 'string' || filename.match(/\..{2,4}$/) || config.autoExt === 0 || config.autoExt === false){
3723
+ config = config || {};
3724
+ if(typeof filename !== 'string' || filename.match(/^[A-z]+:\/\/|\n|\..{2,4}$/) || config.autoExt === 0 || config.autoExt === false){
3679
3725
return filename;
3680
3726
}
3681
3727
return filename+'.'+ext
@@ -3694,7 +3740,15 @@ var fileExists = utils.fileExists = function(path,cb){
3694
3740
cb(false);
3695
3741
});
3696
3742
});
3697
- //*/
3743
+ } else if(utils.isReactNative) {
3744
+ // If ReactNative
3745
+ var RNFS = require('react-native-fs');
3746
+ RNFS.exists(path).then(function(yes){
3747
+ cb && cb(yes);
3748
+ }).catch(function(err){
3749
+ throw err;
3750
+ });
3751
+ //*/
3698
3752
} else {
3699
3753
// TODO Cordova, etc.
3700
3754
throw new Error('You can use exists() only in Node.js or Apach Cordova');
@@ -3721,14 +3775,20 @@ var saveFile = utils.saveFile = function(path, data, cb, opts) {
3721
3775
res = cb(res);
3722
3776
}
3723
3777
} else {
3724
-
3725
3778
if(utils.isNode) {
3726
3779
//*not-for-browser/*
3727
3780
var fs = require('fs');
3728
3781
data = fs.writeFileSync(path,data);
3729
3782
if(cb){
3730
3783
res = cb(res);
3731
3784
}
3785
+ }else if(utils.isReactNative) {
3786
+ var RNFS = require('react-native-fs');
3787
+ RNFS.writeFile(path, data).then(function(success){ //, 'utf8'
3788
+ if(cb) res = cb(res);
3789
+ }).catch(function(err){
3790
+ console.log(err.message);
3791
+ });
3732
3792
} else if(utils.isCordova) {
3733
3793
utils.global.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
3734
3794
@@ -14454,7 +14514,10 @@ alasql.into.CSV = function(filename, opts, data, columns, cb) {
14454
14514
data.forEach(function(d){
14455
14515
s += columns.map(function(col){
14456
14516
var s = d[col.columnid];
14457
- s = (s+"").replace(new RegExp('\\'+opt.quote,"g"),'""');
14517
+ // escape the character wherever it appears in the field
14518
+ if (opt.quote !== '') {
14519
+ s = (s+"").replace(new RegExp('\\'+opt.quote,"g"), opt.quote + opt.quote);
14520
+ }
14458
14521
14459
14522
//Excel 2013 needs quotes around strings - thanks for _not_ complying with RFC for CSV
14460
14523
if(+s!=s){ // jshint ignore:line
0 commit comments