From 68525225703dcc4c19a12e2f092169bea694e997 Mon Sep 17 00:00:00 2001 From: Snider Date: Sun, 23 Jan 2022 20:34:56 +0000 Subject: [PATCH] fmt --- lib/entropy/quasi.test.ts | 16 +++--- lib/entropy/quasi.ts | 114 +++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 63 deletions(-) diff --git a/lib/entropy/quasi.test.ts b/lib/entropy/quasi.test.ts index 8f5783c..3466a77 100644 --- a/lib/entropy/quasi.test.ts +++ b/lib/entropy/quasi.test.ts @@ -1,18 +1,20 @@ import { assertEquals } from "https://deno.land/std@0.122.0/testing/asserts.ts"; -import {EnchantrixEntropyQuasi} from "./quasi.ts"; +import { EnchantrixEntropyQuasi } from "./quasi.ts"; // Compact form: name and function Deno.test("IN: Snider OUT: r3dinS", () => { - const x = new EnchantrixSaltQuasiEntropy('Snider').salty(); - assertEquals(x, 'r3dinS'); + const x = new EnchantrixSaltQuasiEntropy("Snider").salty(); + assertEquals(x, "r3dinS"); }); // Compact form: name and function Deno.test("IN: snider OUT: r3dinz", () => { - const x = new EnchantrixSaltQuasiEntropy('snider').salty(); - assertEquals(x, 'r3dinz'); + const x = new EnchantrixSaltQuasiEntropy("snider").salty(); + assertEquals(x, "r3dinz"); }); Deno.test("IN: a long string with spaces and workds and much letters and stuff OUT: ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014", () => { - const x = new EnchantrixSaltQuasiEntropy('a long string with spaces and workds and much letters and stuff').salty(); - assertEquals(x, 'ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014'); + const x = new EnchantrixSaltQuasiEntropy( + "a long string with spaces and workds and much letters and stuff", + ).salty(); + assertEquals(x, "ffu7zdn4zr37731hcumdn4zdkr0wdn4z3c4pzh7iwgnir7zgn014"); }); diff --git a/lib/entropy/quasi.ts b/lib/entropy/quasi.ts index 8b9b55d..ff0f005 100644 --- a/lib/entropy/quasi.ts +++ b/lib/entropy/quasi.ts @@ -2,68 +2,70 @@ * Reproducible salts from input without prior knowledge */ export class EnchantrixEntropyQuasi { + /** + * Extend to enforce a custom mapping + * + * @protected + */ + // deno-lint-ignore no-explicit-any + protected charMap: any = { + " ": "", + "o": "0", + "l": "1", + "e": "3", + "a": "4", + "s": "z", + "t": "7", + }; - /** - * Extend to enforce a custom mapping - * - * @protected - */ - // deno-lint-ignore no-explicit-any - protected charMap:any = { - ' ': '', - 'o': '0', - 'l': "1", - 'e': "3", - 'a': "4", - 's': "z", - 't': "7", - } + /** + * @type {string} Origin Input + * @protected + */ + protected readonly _input: string = ""; - /** - * @type {string} Origin Input - * @protected - */ - protected readonly _input: string = '' + /** + * Initiate with input to work on + * + * @param input + */ + constructor(input: string) { + this._input = input; + } - /** - * Initiate with input to work on - * - * @param input - */ - constructor(input: string) { - this._input = input - } + /** + * Returns CharMap + * + * @returns {{'[char]': string}} + */ + // deno-lint-ignore no-explicit-any + get keyMap(): any { + return this.charMap; + } - /** - * Returns CharMap - * - * @returns {{'[char]': string}} - */ - // deno-lint-ignore no-explicit-any - get keyMap():any { - return this.charMap - } + /** + * Performs salt on input + * + * @returns {string} Salted Input + */ + salty(): string { + if (!this._input) { + return ""; + } - /** - * Performs salt on input - * - * @returns {string} Salted Input - */ - salty(): string { - if (!this._input) { - return ''; - } + let i: number = this._input.length; - let i: number = this._input.length + const salt: string[] = []; - const salt:string[] = [] - - while (i--) { - // If Char is in the map, use the replaced value; otherwise use original char - salt.push(this.keyMap[this._input[i]] !== undefined ? this.keyMap[this._input[i]] : this._input[i]) - } - - return salt.join('') - } + while (i--) { + // If Char is in the map, use the replaced value; otherwise use original char + salt.push( + this.keyMap[this._input[i]] !== undefined + ? this.keyMap[this._input[i]] + : this._input[i], + ); + } + return salt.join(""); + } }