{"id":16489069,"url":"https://github.com/thundernet8/str2hex","last_synced_at":"2025-03-23T12:34:16.435Z","repository":{"id":44116433,"uuid":"68602187","full_name":"thundernet8/str2hex","owner":"thundernet8","description":"npm package gulp-str2hex to add confusion for your JavaScript code","archived":false,"fork":false,"pushed_at":"2022-02-12T07:30:15.000Z","size":6,"stargazers_count":6,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T13:42:50.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thundernet8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-19T12:10:11.000Z","updated_at":"2020-09-14T11:53:48.000Z","dependencies_parsed_at":"2022-07-22T15:32:02.000Z","dependency_job_id":null,"html_url":"https://github.com/thundernet8/str2hex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fstr2hex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fstr2hex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fstr2hex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thundernet8%2Fstr2hex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thundernet8","download_url":"https://codeload.github.com/thundernet8/str2hex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221851132,"owners_count":16891723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:42:57.930Z","updated_at":"2024-10-28T15:51:45.517Z","avatar_url":"https://github.com/thundernet8.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Note\nThis is a package modified from [confusion](https://www.npmjs.com/package/confusion)\n\n# About\nSometimes, we want to obfuscate our source code to against theft or abuse.\n\n**Confusion** makes it harder to decipher your code by replacing string literals \nand property accesses with lookups into a string map.\n\n**Gulp-str2hex** inherit the basic functionality of Confusion, integrate with gulp, and also bring some enhancement.\n\n* Convert strings and object property names to Hex string like '\\x00' (None ASCII char to '\\u0000' unicode)\n* Compress the code, remove comments, new lines, spaces()\n\n## Install\n\nuse npm:\n\n\n```\nnpm install gulp-str2hex --save\n```\n\n## Example\n\nThis code snippet:\n\n```js\nvar cnStr = \"中文测试\";\nvar enStr = 'This is a sentence in English';\n \nString.prototype.myLog = function () {\n    console.log('\u003e\u003e ' + str + ' \u003c\u003c');\n};\n```\n\nwill be converted to\n\n```js\nvar cnStr = '\\u4e2d\\u6587\\u6d4b\\u8bd5';\nvar enStr = '\\x54\\x68\\x69\\x73\\x20\\x69\\x73\\x20\\x61\\x20\\x73\\x65\\x6e\\x74\\x65\\x6e\\x63\\x65\\x20\\x69\\x6e\\x20\\x45\\x6e\\x67\\x6c\\x69\\x73\\x68';\nString[['\\x70\\x72\\x6f\\x74\\x6f\\x74\\x79\\x70\\x65']][['\\x6d\\x79\\x4c\\x6f\\x67']] = function () {\n    console[['\\x6c\\x6f\\x67']]('\\x3e\\x3e\\x20' + str + '\\x20\\x3c\\x3c');\n};\n```\n\nor use string map\n\n```js\nvar _x28494 = [\n    '\\u4e2d\\u6587\\u6d4b\\u8bd5',\n    '\\x54\\x68\\x69\\x73\\x20\\x69\\x73\\x20\\x61\\x20\\x73\\x65\\x6e\\x74\\x65\\x6e\\x63\\x65\\x20\\x69\\x6e\\x20\\x45\\x6e\\x67\\x6c\\x69\\x73\\x68',\n    '\\x6d\\x79\\x4c\\x6f\\x67',\n    '\\x70\\x72\\x6f\\x74\\x6f\\x74\\x79\\x70\\x65',\n    '\\x6c\\x6f\\x67',\n    '\\x3e\\x3e\\x20',\n    '\\x20\\x3c\\x3c'\n];\nvar cnStr = _x28494[0];\nvar enStr = _x28494[1];\nString[_x28494[3]][_x28494[2]] = function () {\n    console[_x28494[4]](_x28494[5] + str + _x28494[6]);\n};\n```\n\nor bring all the string through call parameter of \u003cabbr title=\"immediately invoced function expression\"\u003eIIFE\u003c/abbr\u003e:\n\n```js\n(function (_x16425) {\n    'use strict';\n    var cnStr = _x16425[0];\n    var enStr = _x16425[1];\n    String[_x16425[3]][_x16425[2]] = function () {\n        console[_x16425[4]](_x16425[5] + str + _x16425[6]);\n    };\n}.call(this, [\n    '\\u4e2d\\u6587\\u6d4b\\u8bd5',\n    '\\x54\\x68\\x69\\x73\\x20\\x69\\x73\\x20\\x61\\x20\\x73\\x65\\x6e\\x74\\x65\\x6e\\x63\\x65\\x20\\x69\\x6e\\x20\\x45\\x6e\\x67\\x6c\\x69\\x73\\x68',\n    '\\x6d\\x79\\x4c\\x6f\\x67',\n    '\\x70\\x72\\x6f\\x74\\x6f\\x74\\x79\\x70\\x65',\n    '\\x6c\\x6f\\x67',\n    '\\x3e\\x3e\\x20',\n    '\\x20\\x3c\\x3c'\n]));\n\n```\n\nyou can also choose only hex some none ASCII chars like Chinese(like what some Chinese to unicode packages to do)\n\n```js\n(function (_x53816) {\n    'use strict';\n    var cnStr = _x53816[0];\n    var enStr = _x53816[1];\n    String[_x53816[3]][_x53816[2]] = function () {\n        console[_x53816[4]](_x53816[5] + str + _x53816[6]);\n    };\n}.call(this, [\n    '\\u4e2d\\u6587\\u6d4b\\u8bd5',\n    'This is a sentence in English',\n    'myLog',\n    'prototype',\n    'log',\n    '\u003e\u003e ',\n    ' \u003c\u003c'\n]));\n```\n\nand compress the code(the uglify-js package will restore what we have converted, so we cannot use it after our working pipe):\n\n```js\n(function(_x37168){'use strict';var cnStr=_x37168[0];var enStr=_x37168[1];String[_x37168[3]][_x37168[2]]=function(){console[_x37168[4]](_x37168[5]+str+_x37168[6]);};}.call(this,['\\u4e2d\\u6587\\u6d4b\\u8bd5','This is a sentence in English','myLog','prototype','log','\u003e\u003e ',' \u003c\u003c']));\n```\n\n## Usage\n\nfirst, import the package\n\n```js\nvar str2hex = require('gulp-str2hex');\n```\n\nuse with gulp\n\n```js\ngulp.src(['./src/js/*.js'])\n    .pipe(webpack(require('./webpack.config.js')))\n    .pipe(uglify())\n    .pipe(str2hex())\n    .pipe(gulp.dest('./assets/js')) \n```\n\nadd some options\n\n```js\ngulp.src(['./src/js/*.js'])\n    .pipe(webpack(require('./webpack.config.js')))\n    .pipe(uglify())\n    .pipe(str2hex({\n        hexall: false,\n        placeholdMode: 2,\n        compress: true\n    }))\n    .pipe(gulp.dest('./assets/js')) \n```\n\n## options\n\n* hexall\n\n  whether hex all strings or not, default: `false`\n\n\n  available values: `true` or `false`\n  \n\n* placeholdMode\n\n  how to map the strings, default: `0`\n\n  \n  available values: \n  ```\n  0 - keep string in their positions,\n  1(alias `prependMap`) - use a array includes all the strings, and expose the array as a variable prepend the code;\n  2(alias `wrapWithIife`) - use a array includes all the strings, and use Iife to wrap the array as a parameter of the function;\n  ```\n\n\n* compress\n\n  compress the code, remove new lines, comments and spaces, instead of **uglify-js**, default true\n\n  available values: `true` or `false`\n\n  **note:**\n    if you use uglify-js, must make the pipe before our package pipe, or the hex string will be restored.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fstr2hex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthundernet8%2Fstr2hex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthundernet8%2Fstr2hex/lists"}