Skip to content

Commit

Permalink
Fixed prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed May 2, 2023
1 parent 78ec864 commit e22b097
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 88 deletions.
8 changes: 5 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
**/**
!**/*.js
!**/*.ts
*
!*.js
!*.ts
.git
.vscode
cjs
dist
esm
types
!src
!test
node_modules
26 changes: 20 additions & 6 deletions src/add.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Adds the given key to each byte of the given data. */
function add(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function add(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function add(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function add(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function add(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function add(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x + k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => (x + k) & 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = add;
24 changes: 19 additions & 5 deletions src/and.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Performs a bitwise AND operation on each byte of the given data using the given key. */
function and(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function and(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function and(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function and(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function and(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function and(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x & k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = and;
26 changes: 20 additions & 6 deletions src/divide.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Divides each byte of the given data by the given key. */
function divide(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function divide(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function divide(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function divide(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function divide(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function divide(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x / k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => (x / k) & 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = divide;
29 changes: 12 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@ export const _internal = {
else if (typeof data == "string") return Buffer.from(data);
else if (ArrayBuffer.isView(data)) return Buffer.from(data.buffer);
else if (data instanceof ArrayBuffer) return Buffer.from(data);
else throw new TypeError("Argument \"data\" must be of type string or an instance of Buffer, TypedArray, DataView, or ArrayBuffer.");
else
throw new TypeError(
'Argument "data" must be of type string or an instance of Buffer, TypedArray, DataView, or ArrayBuffer.'
);
} else {
if (typeof data == "string") return new TextEncoder().encode(data);
else if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer);
else if (ArrayBuffer.isView(data))
return new Uint8Array(data.buffer);
else if (data instanceof ArrayBuffer) return new Uint8Array(data);
else throw new TypeError("Argument \"data\" must be of type string or an instance of TypedArray, DataView, or ArrayBuffer.");
else
throw new TypeError(
'Argument "data" must be of type string or an instance of TypedArray, DataView, or ArrayBuffer.'
);
}
}
}

export {
add,
and,
divide,
multiply,
nand,
nor,
not,
or,
subtract,
xnor,
xor
};

export { add, and, divide, multiply, nand, nor, not, or, subtract, xnor, xor };
26 changes: 20 additions & 6 deletions src/multiply.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Multiplies each byte of the given data by the given key. */
function multiply(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function multiply(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function multiply(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function multiply(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function multiply(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function multiply(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x * k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => (x * k) & 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = multiply;
24 changes: 19 additions & 5 deletions src/nand.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Performs a bitwise NAND operation on each byte of the given data using the given key. */
function nand(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function nand(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function nand(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function nand(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function nand(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function nand(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => (x & k & 255) ^ 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = nand;
26 changes: 20 additions & 6 deletions src/nor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Performs a bitwise NOR operation on each byte of the given data using the given key. */
function nor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function nor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function nor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function nor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function nor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function nor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => (x | k & 255) ^ 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => (x | (k & 255)) ^ 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = nor;
19 changes: 14 additions & 5 deletions src/not.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { _internal } from ".";

/** Performs a bitwise NOT operation on each byte of the given data. */
function not(data: string | ArrayBuffer | NodeJS.ArrayBufferView, encoding: string): string;
function not(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
encoding: string
): string;
function not(data: string | ArrayBuffer | NodeJS.ArrayBufferView): Uint8Array;
function not(data: string | ArrayBuffer | NodeJS.ArrayBufferView, encoding?: string): string | Uint8Array {
const result = _internal.toBuffer(data).map(x => x ^ 255 & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
function not(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
encoding?: string
): string | Uint8Array {
const result = _internal.toBuffer(data).map(x => x ^ (255 & 255));
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = not;
26 changes: 20 additions & 6 deletions src/or.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Performs a bitwise OR operation on each byte of the given data using the given key. */
function or(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function or(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function or(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function or(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function or(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function or(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x | k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => x | (k & 255));
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = or;
26 changes: 20 additions & 6 deletions src/subtract.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Subtracts the given key from each byte of the given data. */
function subtract(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function subtract(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function subtract(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function subtract(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function subtract(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function subtract(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => x - k & 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => (x - k) & 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = subtract;
26 changes: 20 additions & 6 deletions src/xnor.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { _internal } from ".";

/** Performs a bitwise XNOR operation on each byte of the given data using the given key. */
function xnor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding: string): string;
function xnor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number): Uint8Array;
function xnor(data: string | ArrayBuffer | NodeJS.ArrayBufferView, key: number, encoding?: string): string | Uint8Array {
function xnor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding: string
): string;
function xnor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number
): Uint8Array;
function xnor(
data: string | ArrayBuffer | NodeJS.ArrayBufferView,
key: number,
encoding?: string
): string | Uint8Array {
const k = !isNaN(key) ? Number(key) : 0;
const result = _internal.toBuffer(data).map(x => (x ^ k & 255) ^ 255);
return encoding ? ((typeof Buffer != "undefined" && Buffer.isBuffer(result)) ?
result.toString(encoding as BufferEncoding) : new TextDecoder(encoding).decode(result)) : result;
const result = _internal.toBuffer(data).map(x => x ^ (k & 255) ^ 255);
return encoding
? typeof Buffer != "undefined" && Buffer.isBuffer(result)
? result.toString(encoding as BufferEncoding)
: new TextDecoder(encoding).decode(result)
: result;
}

export = xnor;
Loading

0 comments on commit e22b097

Please sign in to comment.