@noscrape/noscrape
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -1,3 +0,3 @@ | ||
import { Glyph } from "opentype.js"; | ||
import { ObfuscationOptions } from "./obfuscation-options"; | ||
import { Glyph, Path } from "opentype.js"; | ||
import { EncryptionCharacterRange } from "./encryption-character-range.enum"; | ||
declare type GlyphObfuscationResult = { | ||
@@ -7,4 +7,6 @@ translation: Map<number, number>; | ||
}; | ||
export declare function obfuscateGlyphs(originalGlyphs: Glyph[], options?: ObfuscationOptions): GlyphObfuscationResult; | ||
export declare function obfuscateGlyphs(originalGlyphs: (Glyph & { | ||
path: Path; | ||
})[], characterRange: EncryptionCharacterRange, strength: number): GlyphObfuscationResult; | ||
export {}; | ||
//# sourceMappingURL=glyph.d.ts.map |
@@ -5,12 +5,8 @@ "use strict"; | ||
const opentype_js_1 = require("opentype.js"); | ||
const encryption_character_range_enum_1 = require("./encryption-character-range.enum"); | ||
function obfuscateGlyphs(originalGlyphs, options) { | ||
var _a; | ||
function obfuscateGlyphs(originalGlyphs, characterRange, strength) { | ||
const translation = new Map(); | ||
const startFromUnicode = (_a = options === null || options === void 0 ? void 0 : options.characterRange) !== null && _a !== void 0 ? _a : encryption_character_range_enum_1.EncryptionCharacterRange.PRIVATE_USE_AREA; | ||
const glyphs = originalGlyphs.map((glyph, index) => { | ||
const unicode = index + startFromUnicode; | ||
const unicode = index + characterRange; | ||
translation.set(glyph.unicode, unicode); | ||
const commands = glyph.path.commands.map((cmd) => { | ||
var _a, _b; | ||
if (!cmd.x || !cmd.y) { | ||
@@ -21,6 +17,8 @@ return cmd; | ||
...cmd, | ||
x: cmd.x + Math.random() * ((_a = options === null || options === void 0 ? void 0 : options.strength) !== null && _a !== void 0 ? _a : 1), | ||
y: cmd.y + Math.random() * ((_b = options === null || options === void 0 ? void 0 : options.strength) !== null && _b !== void 0 ? _b : 1), | ||
x: cmd.x + Math.random() * strength, | ||
y: cmd.y + Math.random() * strength, | ||
}; | ||
}); | ||
const { path } = glyph; | ||
path.commands = commands; | ||
return new opentype_js_1.Glyph({ | ||
@@ -30,8 +28,4 @@ index, | ||
unicode, | ||
path: { | ||
...glyph.path, | ||
commands, | ||
}, | ||
path, | ||
advanceWidth: glyph.advanceWidth, | ||
leftSideBearing: glyph.leftSideBearing, | ||
}); | ||
@@ -38,0 +32,0 @@ }); |
@@ -8,2 +8,3 @@ "use strict"; | ||
const opentype_js_1 = require("opentype.js"); | ||
const obfuscation_options_1 = require("./obfuscation-options"); | ||
const glyph_1 = require("./glyph"); | ||
@@ -19,5 +20,6 @@ const font_1 = require("./font"); | ||
async function obfuscate(value, fontFilePath, options) { | ||
const font = await (0, opentype_js_1.load)(fontFilePath, null, {}); | ||
const { characterRange, strength, lowMemory } = { ...obfuscation_options_1.DEFAULT_OPTIONS, ...options }; | ||
const font = (0, opentype_js_1.loadSync)(fontFilePath, { lowMemory }); | ||
const originalGlyphs = (0, value2glyphs_1.default)(value, font); | ||
const { translation, glyphs } = (0, glyph_1.obfuscateGlyphs)(originalGlyphs, options); | ||
const { translation, glyphs } = (0, glyph_1.obfuscateGlyphs)(originalGlyphs, characterRange, strength); | ||
const buffer = (0, font_1.generateObfuscatedFont)(font, glyphs); | ||
@@ -24,0 +26,0 @@ const obj = (0, value_1.obfuscateValue)(value, translation); |
import { EncryptionCharacterRange } from "./encryption-character-range.enum"; | ||
export interface ObfuscationOptions { | ||
/** | ||
* obfuscation strength multiplier (default: 1) | ||
* optional: obfuscation strength multiplier (default: 1) | ||
* all under 0.1 makes no sense (can simply be rounded and so back calculated) | ||
@@ -10,6 +10,18 @@ * all over 10 makes no sense (looks like 💩) | ||
/** | ||
* the character-range to pick obfuscation glyphs from | ||
* optional: the character-range to pick obfuscation glyphs from | ||
*/ | ||
characterRange?: EncryptionCharacterRange; | ||
/** | ||
* optional: lowMemory option | ||
* use if to less memory availible for loading font | ||
*/ | ||
lowMemory?: boolean; | ||
} | ||
interface ObfuscationDefaultOptions extends ObfuscationOptions { | ||
strength: number; | ||
characterRange: EncryptionCharacterRange; | ||
lowMemory: boolean; | ||
} | ||
export declare const DEFAULT_OPTIONS: ObfuscationDefaultOptions; | ||
export {}; | ||
//# sourceMappingURL=obfuscation-options.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_OPTIONS = void 0; | ||
const encryption_character_range_enum_1 = require("./encryption-character-range.enum"); | ||
exports.DEFAULT_OPTIONS = { | ||
strength: 1, | ||
characterRange: encryption_character_range_enum_1.EncryptionCharacterRange.PRIVATE_USE_AREA, | ||
lowMemory: false, | ||
}; | ||
//# sourceMappingURL=obfuscation-options.js.map |
@@ -1,3 +0,5 @@ | ||
import { Font, Glyph } from "opentype.js"; | ||
export default function value2glyphs<T>(value: T, font: Font): Glyph[]; | ||
import { Font, Glyph, Path } from "opentype.js"; | ||
export default function value2glyphs<T>(value: T, font: Font): (Glyph & { | ||
path: Path; | ||
})[]; | ||
//# sourceMappingURL=value2glyphs.d.ts.map |
@@ -26,3 +26,3 @@ "use strict"; | ||
const glyphs = font.stringToGlyphs(lodash_1.default.shuffle(uniqChars).join("")); | ||
const notDefGlyph = font.glyphs.glyphs[0]; | ||
const notDefGlyph = font.glyphs.get(0); | ||
glyphs.unshift(notDefGlyph); | ||
@@ -29,0 +29,0 @@ return glyphs; |
{ | ||
"name": "@noscrape/noscrape", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "protect your content from scraping", | ||
@@ -38,7 +38,3 @@ "homepage": "https://noscrape-nexample.vercel.app", | ||
"@types/lodash": "^4.14.182", | ||
"jest": "^28.1.0", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^28.0.2", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4", | ||
"@types/opentype.js": "^1.3.3", | ||
"eslint": "^8.15.0", | ||
@@ -49,4 +45,9 @@ "eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-prettier": "^4" | ||
"eslint-plugin-prettier": "^4", | ||
"jest": "^28.1.0", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^28.0.2", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4" | ||
} | ||
} |
@@ -27,3 +27,3 @@ | ||
# Concept | ||
The key behind is to use any true-type font from which _noscrape_ generates a new version with shuffeld unicodes and nothing what one can use to calculate them back. Strings and Integers become obfuscated and are only readable by using the generated obfuscation-font. | ||
The key behind is to use any true-type font from which _noscrape_ generates a new version with shuffled unicodes and nothing what one can use to calculate them back. Strings and Integers become obfuscated and are only readable by using the generated obfuscation-font. | ||
@@ -57,6 +57,9 @@ <br /><br /> | ||
const object = { title: "noscrape", text: "obfuscation" } | ||
const { font, value } = obfuscate<any>(object, 'path/to/your/font.ttf') | ||
const { font, value } = obfuscate(object, 'path/to/your/font.ttf') | ||
``` | ||
⬇⬇⬇⬇ provide data ⬇⬇⬇⬇ | ||
<br /> | ||
<p style="text-align: center">⬇⬇⬇⬇ provide data ⬇⬇⬇⬇</p> | ||
<br /> | ||
```javascript | ||
@@ -87,3 +90,3 @@ // font will be provided as buffer | ||
[example-code](https://github.com/schoenbergerb/noscrape-nexample) | ||
[example-code](https://github.com/schoenbergerb/noscrape-example) | ||
@@ -97,29 +100,36 @@ [live demo](https://noscrape-nexample.vercel.app) | ||
<br /> | ||
## strength | ||
* obfuscation strength multiplier ( default: 1 ) | ||
* all under 0.1 makes no sense ( paths can be simply back calculated ) | ||
* all over 10 makes no sense ( looks like 💩 ) | ||
##### obfuscation strength multiplier ( default: 1 ) | ||
##### all under 0.1 makes no sense ( paths can be simply back calculated ) | ||
##### all over 10 makes no sense ( looks like 💩 ) | ||
<img src="./docs/obfuscationstrength.jpg"> | ||
<br /> | ||
<br /> | ||
## characterRange | ||
[character range](https://www.ling.upenn.edu/courses/Spring_2003/ling538/UnicodeRanges.html) used for encryption | ||
##### [character range](https://www.ling.upenn.edu/courses/Spring_2003/ling538/UnicodeRanges.html) used for encryption | ||
- PRIVATE_USE_AREA ___DEFAULT___ | ||
- LATIN | ||
- GREEK | ||
- CYRILLIC | ||
- HIRAGANA | ||
- KATAKANA | ||
###### PRIVATE_USE_AREA ___DEFAULT___ | ||
###### LATIN | ||
###### GREEK | ||
###### CYRILLIC | ||
###### HIRAGANA | ||
###### KATAKANA | ||
<br /> | ||
<br /> | ||
<br /> | ||
<br /> | ||
## lowMemory | ||
##### use only if you do not have a lot of memory and noscrape cannot load the given font file | ||
###### DEFAULT: **false** | ||
<br /> | ||
<br /> | ||
<br /> | ||
# Contributions | ||
@@ -126,0 +136,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28712
331
142
15