Skip to content

Commit

Permalink
Merge pull request #24 from heldinz/formatting
Browse files Browse the repository at this point in the history
Formatting
  • Loading branch information
heldinz authored Aug 16, 2024
2 parents ace0e99 + fe3a77d commit 6ad2086
Show file tree
Hide file tree
Showing 9 changed files with 3,797 additions and 2,981 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
logs
*.log
package-lock.json
node_modules
*.png
.git*
.nyc_output
coverage
fixtures
.husky
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"singleQuote": true,
"useTabs": true,
"overrides": [
{
"files": [".*rc", "*.json"],
"options": { "parser": "json" }
}
]
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ npm install --save-dev gulp-convert-encoding
## Usage

```js
var gulp = require("gulp");
var convertEncoding = require("gulp-convert-encoding");
var gulp = require('gulp');
var convertEncoding = require('gulp-convert-encoding');

gulp.task("default", function () {
gulp.task('default', function () {
return gulp
.src("src/file.txt")
.pipe(convertEncoding({ to: "iso-8859-15" }))
.pipe(gulp.dest("dist"));
.src('src/file.txt')
.pipe(convertEncoding({ to: 'iso-8859-15' }))
.pipe(gulp.dest('dist'));
});
```

Expand Down
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ module.exports = function (options) {
options = options || {};

if (!options.from && !options.to) {
throw new pluginError('gulp-convert-encoding', 'At least one of `from` or `to` required');
throw new pluginError(
'gulp-convert-encoding',
'At least one of `from` or `to` required',
);
}

options.from = options.from || UTF8;
options.to = options.to || UTF8;
options.iconv = options.iconv ? options.iconv :
{decode: {}, encode: {}};
options.iconv = options.iconv ? options.iconv : { decode: {}, encode: {} };

return through.obj(function (file, enc, cb) {

if (file.isNull()) {
this.push(file);
cb();
Expand All @@ -39,7 +40,11 @@ module.exports = function (options) {

if (file.isBuffer()) {
try {
var content = iconv.decode(file.contents, options.from, options.iconv.decode);
var content = iconv.decode(
file.contents,
options.from,
options.iconv.decode,
);
file.contents = iconv.encode(content, options.to, options.iconv.encode);
this.push(file);
} catch (err) {
Expand Down
Loading

0 comments on commit 6ad2086

Please sign in to comment.