+6
-6
@@ -105,8 +105,8 @@ 'use strict' | ||
| for (let entry of homographs) { | ||
| entry = entry.split('') | ||
| const ascii = entry.splice(0, 1)[0] | ||
| for (let char of entry) { | ||
| reverse.set(char, ascii) | ||
| } | ||
| dict.set(ascii, entry) | ||
| entry = Array.from(entry) | ||
| const ascii = entry.splice(0, 1)[0] | ||
| for (let char of entry) { | ||
| reverse.set(char, ascii) | ||
| } | ||
| dict.set(ascii, entry) | ||
| } | ||
@@ -113,0 +113,0 @@ |
+13
-10
@@ -12,6 +12,6 @@ 'use strict' | ||
| probability: 33, | ||
| only: null | ||
| chars: '' | ||
| }, opts) | ||
| return replace(text, dict, () => Math.random() < (opts.probability / 100)) | ||
| return replace(text, dict, () => Math.random() < (opts.probability / 100), opts) | ||
| } | ||
@@ -23,3 +23,3 @@ | ||
| function replace (text, dict, condition) { | ||
| function replace (text, dict, condition, options) { | ||
| const original = text | ||
@@ -29,11 +29,14 @@ let pos = 0 | ||
| for (let char of original) { | ||
| const replacement = dict.get(char) | ||
| const isInArray = (options.chars.length && options.chars.includes(char)) | ||
| if (isInArray || !options.chars.length) { | ||
| const replacement = dict.get(char) | ||
| if (replacement !== undefined) { | ||
| const fakeLetter = Array.isArray(replacement) ? replacement[Math.floor(Math.random() * replacement.length)] : replacement | ||
| if (replacement !== undefined) { | ||
| const fakeLetter = Array.isArray(replacement) ? replacement[Math.floor(Math.random() * replacement.length)] : replacement | ||
| if (typeof condition === 'function') { | ||
| if (condition()) text = splice(text, pos, 1, fakeLetter) | ||
| } else { | ||
| text = splice(text, pos, 1, fakeLetter) | ||
| if (typeof condition === 'function') { | ||
| if (condition()) text = splice(text, pos, 1, fakeLetter) | ||
| } else { | ||
| text = splice(text, pos, 1, fakeLetter) | ||
| } | ||
| } | ||
@@ -40,0 +43,0 @@ } |
+1
-1
| { | ||
| "name": "homoglyph", | ||
| "version": "1.0.2", | ||
| "version": "1.1.0", | ||
| "description": "Replace ascii chars with their same looking utf8 chars.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+4
-5
| import test from 'ava' | ||
| import { encode } from './' | ||
| import fs from 'fs'; | ||
| test('encode', t => { | ||
| const output = encode('text', { probability: 100 }) | ||
| console.log(output) | ||
| t.pass() | ||
| t.end() | ||
| const output = encode('text ;', { probability: 100, chars: ' ;' }) | ||
| console.log(output) | ||
| t.pass() | ||
| t.end() | ||
| }) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7943
2.16%154
1.32%0
-100%