New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grunt-iconv

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-iconv - npm Package Compare versions

Comparing version

to
0.0.2

9

package.json
{
"name": "grunt-iconv",
"description": "change file encoding",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "https://github.com/amdgigabyte/grunt-iconv",

@@ -42,3 +42,6 @@ "author": {

"gruntplugin"
]
}
],
"readme": "# grunt-iconv\n\n> change file encoding\n\n## Getting Started\nThis plugin requires Grunt `~0.4.1`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-iconv --save-dev\n```\n\nOne the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-iconv');\n```\n\n## The \"iconv\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `iconv` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n iconv: {\n options: {\n // Task-specific options go here.\n },\n your_target: {\n // Target-specific file lists and/or options go here.\n },\n },\n})\n```\n\n### Options\n\n#### options.separator\nType: `String`\nDefault value: `', '`\n\nA string value that is used to do something with whatever.\n\n#### options.punctuation\nType: `String`\nDefault value: `'.'`\n\nA string value that is used to do something else with whatever else.\n\n### Usage Examples\n\n#### Default Options\nIn this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`\n\n```js\ngrunt.initConfig({\n iconv: {\n options: {},\n files: {\n 'dest/default_options': ['src/testing', 'src/123'],\n },\n },\n})\n```\n\n#### Custom Options\nIn this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`\n\n```js\ngrunt.initConfig({\n iconv: {\n options: {\n separator: ': ',\n punctuation: ' !!!',\n },\n files: {\n 'dest/default_options': ['src/testing', 'src/123'],\n },\n },\n})\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n_(Nothing yet)_\n",
"_id": "grunt-iconv@0.0.1",
"_from": "grunt-iconv"
}

@@ -13,26 +13,11 @@ /*

var fs = require('fs');
var fs = require('fs'),
iconv = require('iconv-lite');
grunt.registerMultiTask('iconv', 'change file encoding', function() {
/**
* @param {Buffer\String} 要unicode的对象
* @param {Boolean} flag 编码后所带的前缀。 为true 则为\U,在js文件中可用;为false,则为\,在css文件中可用
*/
function escapeIt(buf){
var f_charset,t_charset;
var str = iconv.decode(buf,'gbk');
var ret = iconv.encode(str,'utf8');
return ret;
}
grunt.registerMultiTask('parseunicode', 'parse unicode', function() {
var str, buffer, charset, type;
this.data.options = this.data.options || {};
charset = this.data.options.charset || 'utf8';
type = this.data.options.type !== 'js' ? false : true ;
f_charset = this.data.options.from_charset || 'utf8';
t_charset = this.data.options.to_charset || 'utf8';

@@ -42,5 +27,6 @@ this.files.forEach(function(files){

var buffer = grunt.file.read(file, {
encoding: charset
encoding: f_charset
});
fs.writeFileSync(file, escapeIt(buffer, type));
fs.writeFileSync(file, buffer, t_charset);
});

@@ -47,0 +33,0 @@ });