Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from schoenbergerb/improve-project-structure
Browse files Browse the repository at this point in the history
Improve project structure
  • Loading branch information
schoenbergerb authored May 17, 2022
2 parents 6763246 + 587d877 commit 33c512e
Show file tree
Hide file tree
Showing 15 changed files with 5,681 additions and 2,400 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": [
"airbnb-base",
"airbnb-typescript/base",
"plugin:prettier/recommended"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"import/prefer-default-export": "off",
"import/no-default-export": "error"
},

}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<img src="./docs/preview.png">


<img src="./docs/preview.png">
<br />
<br />

[![GitHub release](https://img.shields.io/github/release/schoenbergerb/noscrape?include_prereleases=&sort=semver&color=blue)](https://github.com/schoenbergerb/noscrape/releases/)
[![License](https://img.shields.io/badge/License-MIT-blue)](#license)
[![issues - noscrape](https://img.shields.io/github/issues/schoenbergerb/noscrape)](https://github.com/schoenbergerb/noscrape/issues)
![Known Vulnerabilities](https://snyk.io/test/github/schoenbergerb/noscrape/badge.svg)
![CodeQL](https://github.com/schoenbergerb/noscrape/workflows/CodeQL/badge.svg)



<br />
<br />


# Project Goal

### this project should help you to prevent anyone from scraping your content
Expand Down
7,973 changes: 5,617 additions & 2,356 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@noscrape/noscrape",
"version": "0.3.1",
"version": "0.4.0",
"description": "protect your content from scraping",
"homepage": "https://noscrape-nexample.vercel.app",
"keywords": [
Expand Down Expand Up @@ -32,13 +32,19 @@
"opentype.js": "^1.3.4"
},
"devDependencies": {
"@babel/preset-typescript": "^7.16.0",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.178",
"jest": "^27.4.4",
"prettier": "^2.5.1",
"ts-jest": "^27.1.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.3"
"@babel/preset-typescript": "^7.17.12",
"@types/jest": "^27.5.1",
"@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",
"eslint": "^8.15.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4"
}
}
2 changes: 1 addition & 1 deletion src/font.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Font } from "opentype.js";

export default function generateObfuscatedFont(font, glyphs) {
export function generateObfuscatedFont(font, glyphs) {
const newFont = new Font({
familyName: "noscrape",
styleName: "obfuscated",
Expand Down
2 changes: 1 addition & 1 deletion src/glyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Glyph } from "opentype.js";
import { EncryptionCharacterRange } from "./encryption-character-range.enum";
import { ObfuscationOptions } from "./obfuscation-options";

export default function obfuscateGlyphs(
export function obfuscateGlyphs(
originalGlyphs: Glyph[],
options?: ObfuscationOptions
) {
Expand Down
5 changes: 1 addition & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
import obfuscate from "./obfuscate";

export * from "./obfuscate";
export * from "./encryption-character-range.enum";

export default obfuscate;
8 changes: 4 additions & 4 deletions src/obfuscate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { load } from "opentype.js";
import { ObfuscationOptions } from "./obfuscation-options";
import obfuscateGlyphs from "./glyph";
import generateObfuscatedFont from "./font";
import { obfuscateGlyphs } from "./glyph";
import { generateObfuscatedFont } from "./font";
import value2glyphs from "./value2glyphs";
import obfuscateValue from "./obfuscate/value";
import { obfuscateValue } from "./obfuscate/value";

/**
* @param value object which will be translated
* @param fontFilePath
* @returns font-family string
*/
export default async function obfuscate<T>(
export async function obfuscate<T>(
value: T,
fontFilePath: string,
options?: ObfuscationOptions
Expand Down
4 changes: 2 additions & 2 deletions src/obfuscate/number.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import obfuscateString from "./string";
import { obfuscateString } from "./string";

export default function obfuscateNumber(n: number, translation) {
export function obfuscateNumber(n: number, translation) {
return obfuscateString(`${n}`, translation);
}
12 changes: 6 additions & 6 deletions src/obfuscate/object.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import _ from "lodash";
import obfuscateNumber from "./number";
import obfuscateString from "./string";
import { clone } from "lodash";
import { obfuscateNumber } from "./number";
import { obfuscateString } from "./string";

export default function obfuscateObject<T>(
export function obfuscateObject<T>(
value: T,
translation: Map<number, number>
): T {
const obj = _.clone(value);
const obj = clone(value);

Object.keys(obj).map((key) => {
Object.keys(obj).forEach((key) => {
switch (typeof obj[key]) {
case "number":
obj[key] = obfuscateNumber(value[key], translation);
Expand Down
2 changes: 1 addition & 1 deletion src/obfuscate/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function obfuscateString(str: string, translation) {
export function obfuscateString(str: string, translation) {
const codes: number[] = str.split("").map((c) => {
const code = c.charCodeAt(0);
return translation.get(code) ?? 0;
Expand Down
11 changes: 5 additions & 6 deletions src/obfuscate/value.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import _ from "lodash";
import obfuscateNumber from "./number";
import obfuscateObject from "./object";
import obfuscateString from "./string";
import { obfuscateNumber } from "./number";
import { obfuscateObject } from "./object";
import { obfuscateString } from "./string";

export default function obfuscateValue<T>(
export function obfuscateValue<T>(
value: T | string | number,
translation: Map<number, number>
): T | string | number {
Expand All @@ -15,6 +14,6 @@ export default function obfuscateValue<T>(
case "object":
return obfuscateObject(value, translation);
default:
throw new Error(typeof value + " could not be obfuscated");
throw new Error(`${typeof value} could not be obfuscated`);
}
}
8 changes: 4 additions & 4 deletions src/obfuscation-options.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EncryptionCharacterRange } from ".";
import { EncryptionCharacterRange } from "./encryption-character-range.enum";

export interface ObfuscationOptions {
/**
* obfuscation strength multiplier ( default: 1 )
* all under 0.1 makes no sense ( can simply be rounded and so back calculated )
* all over 10 makes no sense ( looks like 💩 )
* obfuscation strength multiplier (default: 1)
* all under 0.1 makes no sense (can simply be rounded and so back calculated)
* all over 10 makes no sense (looks like 💩)
*/
strength?: number;

Expand Down
3 changes: 1 addition & 2 deletions test/noscrape.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EncryptionCharacterRange } from '../src/encryption-character-range.enum';
import obfuscate from '../src/obfuscate'
import { obfuscate, EncryptionCharacterRange } from '../src'

const demoObject = {
a: "abcdefghijklmnopqrstuvwxyz",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"exclude": [
"node_modules",
"test",
"example"
"example",
"test"
]
}

0 comments on commit 33c512e

Please sign in to comment.