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

Commit

Permalink
prettify code
Browse files Browse the repository at this point in the history
  • Loading branch information
schoenbergerb committed Jan 3, 2022
1 parent 835af33 commit 0355706
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import obfuscate from "./obfuscate";

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

export default obfuscate;
2 changes: 1 addition & 1 deletion src/obfuscate/number.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import obfuscateString from "./string";

export default function obfuscateNumber(n: number, translation) {
return obfuscateString(`${n}`, translation)
return obfuscateString(`${n}`, translation);
}
2 changes: 1 addition & 1 deletion src/obfuscate/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import obfuscateString from "./string";
export default function obfuscateObject<T>(
value: T,
translation: Map<number, number>
): T {
): T {
const obj = _.clone(value);

Object.keys(obj).map((key) => {
Expand Down
25 changes: 11 additions & 14 deletions src/obfuscate/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@ import obfuscateString from "./string";
export default function obfuscateValue<T>(
value: T | string | number,
translation: Map<number, number>
): T | string | number {

switch (typeof value) {
case "number":
return obfuscateNumber(value, translation);
case "string":
return obfuscateString(value, translation);
case "object":
return obfuscateObject(value, translation);
default:
throw new Error(typeof value + ' could not be obfuscated');
}
): T | string | number {
switch (typeof value) {
case "number":
return obfuscateNumber(value, translation);
case "string":
return obfuscateString(value, translation);
case "object":
return obfuscateObject(value, translation);
default:
throw new Error(typeof value + " could not be obfuscated");
}
}


2 changes: 0 additions & 2 deletions src/obfuscation-options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EncryptionCharacterRange } from ".";

export interface ObfuscationOptions {

/**
* obfuscation strength multiplier ( default: 1 )
* all under 0.1 makes no sense ( can simply be rounded and so back calculated )
Expand All @@ -13,5 +12,4 @@ export interface ObfuscationOptions {
* the character-range to pick obfuscation glyphs from
*/
characterRange?: EncryptionCharacterRange;

}
15 changes: 6 additions & 9 deletions src/value2glyphs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import _ from "lodash";
import { Font, Glyph } from "opentype.js";



const values = (object) => {

if (typeof object === 'number') {
object = `${object}`
if (typeof object === "number") {
object = `${object}`;
}

return _.flatten(
Expand All @@ -28,11 +25,11 @@ export default function value2glyphs<T>(value: T, font: Font): Glyph[] {

const uniqChars = _.union(chars);

const glyphs = font.stringToGlyphs(_.shuffle(uniqChars).join(""));
const glyphs = font.stringToGlyphs(_.shuffle(uniqChars).join(""));

const notDefGlyph = font.glyphs.glyphs[0]
const notDefGlyph = font.glyphs.glyphs[0];

glyphs.unshift(notDefGlyph)
glyphs.unshift(notDefGlyph);

return glyphs
return glyphs;
}

0 comments on commit 0355706

Please sign in to comment.