diff --git a/.vscode/launch.json b/.vscode/launch.json index 99ec7e8..ccebac7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,8 @@ "name": "Launch via NPM", "request": "launch", "runtimeArgs": [ - "test" + "run", + "demo" ], "runtimeExecutable": "npm", "skipFiles": [ diff --git a/example/demo.ts b/example/demo.ts new file mode 100644 index 0000000..373c983 --- /dev/null +++ b/example/demo.ts @@ -0,0 +1,25 @@ +import obfuscate from '../src' +import { EncryptionCharakterRange } from '../src/encryption-character-range.enum' +import fs from 'fs' + +obfuscate( + { data: "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!§$%&/()=?¬”#£fi^``-,.-M:;_,,;#+#+äölü"}, + __dirname + "/example.ttf", + { characterRange: EncryptionCharakterRange.KATAKANA } +).then(({value, font}) => { + fs.writeFileSync('./example.html', ` + + + + + + ${value.data} + + + `) +}) \ No newline at end of file diff --git a/package.json b/package.json index dd12256..6f519b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noscrape/noscrape", - "version": "0.1.6", + "version": "0.1.7", "description": "protect your content from scraping", "homepage": "https://noscrape-nexample.vercel.app", "keywords": ["scraping", "noscrape", "crawler", "websecurity", "scrape", "obfuscation", "obfuscate", "defend", "protection"], @@ -8,7 +8,8 @@ "scripts": { "run": "ts-node main.ts", "build": "tsc", - "test": "jest" + "test": "jest", + "demo": "ts-node example/demo.ts" }, "author": "Bernhard Schönberger", "license": "MIT", diff --git a/src/encryption-character-range.enum.ts b/src/encryption-character-range.enum.ts index db220af..d3da4f0 100644 --- a/src/encryption-character-range.enum.ts +++ b/src/encryption-character-range.enum.ts @@ -15,8 +15,8 @@ export enum EncryptionCharakterRange { /* 0590 - 05FF Hebrew */ HEBREW = 1424, - /* E000 - F8FF Private Use Area */ - DEFAULT = 57344, + /* E000 - F8FF Private Use Area - DEFAULT */ + PRIVATE_USE_AREA = 57344, /* 3040 - 309F Hiragana */ HIRAGANA = 12352, diff --git a/src/glyph.ts b/src/glyph.ts index 49ad3e6..f622c5d 100644 --- a/src/glyph.ts +++ b/src/glyph.ts @@ -9,7 +9,7 @@ export default function obfuscateGlyphs( const translation = new Map(); const startFromUnicode = - options?.characterRange ?? EncryptionCharakterRange.DEFAULT; + options?.characterRange ?? EncryptionCharakterRange.PRIVATE_USE_AREA; const glyphs = originalGlyphs.map((glyph, index) => { const unicode = index + startFromUnicode; @@ -37,6 +37,7 @@ export default function obfuscateGlyphs( commands, }, advanceWidth: glyph.advanceWidth, + leftSideBearing: glyph.leftSideBearing, }); }); diff --git a/src/value2glyphs.ts b/src/value2glyphs.ts index 1ac0c99..5fcbdb8 100644 --- a/src/value2glyphs.ts +++ b/src/value2glyphs.ts @@ -21,5 +21,11 @@ export default function value2glyphs(value: T, font: Font): Glyph[] { const uniqChars = _.union(chars); - return font.stringToGlyphs(_.shuffle(uniqChars).join("")); + const glyphs = font.stringToGlyphs(_.shuffle(uniqChars).join("")); + + const notDefGlyph = font.glyphs.glyphs[0] + + glyphs.unshift(notDefGlyph) + + return glyphs }