-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes convert result will be \uXXXX. #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.idea | ||
.iml | ||
node_modules | ||
*-converted.js | ||
*.log | ||
test/test-output | ||
*.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,14 @@ function native2ascii(str) { | |
|
||
|
||
function ascii2native(str) { | ||
return unescape(str.split('\\').join('%')); | ||
if(str.indexOf('\\\\u')>-1){ | ||
// fix err js minify string | ||
return ascii2native.call(null, str.replace(/\\(\\u(\w+){4})/g, function (all, key) { | ||
return key; | ||
})); | ||
}else{ | ||
return unescape(str.split('\\').join('%')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or process string by default way. |
||
} | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "gulp-native2ascii", | ||
"description": "native2ascii plugin for gulp", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/adamme/gulp-native2ascii", | ||
"author": { | ||
"name": "Adam Lau", | ||
|
@@ -29,15 +29,14 @@ | |
"gulp", | ||
"native2ascii" | ||
], | ||
"scripts": { | ||
"test": "node test/test.js" | ||
}, | ||
"scripts": { | ||
"test": "node test/test.js" | ||
}, | ||
"dependencies": { | ||
"gulp-util": "^2.2.14", | ||
"through2": "^0.4.1" | ||
}, | ||
"devDependencies": { | ||
"gulp-mocha": "^0.4.1", | ||
"gulp-rename": "^1.1.0" | ||
"del": "^0.1.3" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think use different dir for test-cases and test-output is more clearly,:D |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('你好,世界!'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('\\u7f16\\u7801\\u8f6c\\u6362'); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
var n2a = require('../'); | ||
var rename = require('gulp-rename'); | ||
var gulp = require('gulp'); | ||
var gulp = require('gulp'), | ||
n2a = require('../'), | ||
del = require('del'); | ||
|
||
const TEST_CASE = './test/cases/'; | ||
const OUTPUT = './test/test-output/'; | ||
|
||
gulp.src('./**/default.js', {buffer: false}) | ||
.pipe(n2a()) | ||
.pipe(rename(function (path) { | ||
path.basename += "-converted"; | ||
})) | ||
.pipe(gulp.dest('./')); | ||
/** 1. clean up output files. **/ | ||
del([OUTPUT], function (err) { | ||
if (err) { | ||
console.error("clean up output files failed."); | ||
} else { | ||
testCase(); | ||
} | ||
}); | ||
|
||
gulp.src('./**/reverse.js') | ||
.pipe(n2a({ | ||
reverse: true | ||
})) | ||
.pipe(rename(function (path) { | ||
path.basename += "-converted"; | ||
})) | ||
.pipe(gulp.dest('./')); | ||
function testCase() { | ||
/** 2. convert unicode to ascii. **/ | ||
gulp.src(TEST_CASE + 'default.js', {buffer: false}) | ||
.pipe(n2a()) | ||
.pipe(gulp.dest(OUTPUT)); | ||
|
||
/** 3. convert ascii to unicode. **/ | ||
gulp.src(TEST_CASE + 'reverse.js') | ||
.pipe(n2a({ | ||
reverse: true | ||
})) | ||
.pipe(gulp.dest(OUTPUT)); | ||
|
||
/** 4. fixs error uglify ascii string to unicode **/ | ||
gulp.src(TEST_CASE + 'errMinify.js') | ||
.pipe(n2a({ | ||
reverse: true | ||
})) | ||
.pipe(gulp.dest(OUTPUT)); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There're some template engine will render "\u1234" -> "\u1234", so it seems to restore the string one by one.