Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rjutils-collection

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rjutils-collection - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

lib/cjs/loadEnv.d.js

86

lib/cjs/index.d.ts
/// <reference types="node" />
import { Hash } from "crypto";
import randomStrOptions from "./interfaces/randomStrOptions";
import encryptStrOptions from "./interfaces/encryptStrOptions";
import decryptStrOptions from "./interfaces/decryptStrOptions";
import hashStrOptions from "./interfaces/hashStrOptions";
declare const _default: {
/** Load an Env File to JSON */
loadEnv(filePath: string): {
[key: string]: string;
};
/** Generate a Random Number */
randomNum(min: number, max: number, dec?: number): number;
/** Generate a Random Boolean */
randomBol(): boolean;
/** Generate a Random String */
randomStr(options: randomStrOptions): string;
/** Generate a Text Spinner */
spinner: {
new (states?: string[]): {
states: string[];
state: number;
/** Get the Current State */
get(): string;
};
};
/** Encrypt a String */
encryptStr(options: encryptStrOptions): string;
/** Decrypt a String */
decryptStr(options: decryptStrOptions): string;
/** Hash a String */
hashStr(options: hashStrOptions): string | Hash;
};
export = _default;
import randomStrOptions from "./types/randomStrOptions";
import encryptStrOptions from "./types/encryptStrOptions";
import decryptStrOptions from "./types/decryptStrOptions";
import hashStrOptions from "./types/hashStrOptions";
export declare const Version: string;
export { randomStrOptions, encryptStrOptions, decryptStrOptions, hashStrOptions };
/**
* Load an Env File as Object
* @since 1.0.0
*/ export declare function loadEnv<F, A extends boolean | undefined>(
/** The path to the Env file */ file: string,
/** Whether to load the File Async */ isAsync: boolean): A extends true ? Promise<Record<string, string>> : Record<string, string>;
/**
* Generate a Random Number
* @since 1.0.0
*/ export declare function randomNum(
/** The Minimum Number */ min: number,
/** The Maximum Number */ max: number,
/**
* The Decimal Places to Generate
* @default 0
*/ dec?: number): number;
/**
* Generate a Random Boolean
* @since 1.0.1
*/ export declare function randomBol(): boolean;
/**
* Generate a Random String
* @since 1.0.0
*/ export declare function randomStr(options?: randomStrOptions): string;
/**
* Generate a Text Spinner
* @since 1.0.2
*/ export declare class Spinner {
states: string[];
state: number;
/** Create a Spinner */
constructor(
/** The States */ states?: string[]);
/** Get the Current State */
get(): string;
}
/**
* Encrypt a String
* @since 1.0.3
*/ export declare function encryptStr(options?: encryptStrOptions): string;
/**
* Decrypt a String
* @since 1.0.3
*/ export declare function decryptStr(options?: decryptStrOptions): string;
/**
* Hash a String
* @since 1.0.4
*/ export declare function hashStr<T extends hashStrOptions>(options?: hashStrOptions): T['output'] extends 'bytes' ? Hash : string;

@@ -1,2 +0,193 @@

var T=Object.create;var S=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var D=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of M(e))!C.call(t,s)&&s!==r&&S(t,s,{get:()=>e[s],enumerable:!(n=H(e,s))||n.enumerable});return t};var p=(t,e,r)=>(r=t!=null?T(q(t)):{},D(e||!t||!t.__esModule?S(r,"default",{value:t,enumerable:!0}):r,t));var B=x((R,v)=>{var k=p(require("crypto")),l,y,O=()=>{(l===void 0||l>=y.length)&&(l=0,y=k.randomBytes(256));let t=y[l];return l+=1,t},J=t=>{let e=O();for(;e>=256-256%t;)e=O();return e%t},N="abcdefghijklmnopqrstuvwxyz",L="ABCDEFGHIJKLMNOPQRSTUVWXYZ",$="0123456789",A='!@#$%^&*()+_-=}{[]|:;"/?.><,`~',F=(t,e)=>{let r=t.length,n=e.length,s="";for(let o=0;o<r;o++)s+=e[J(n)];return s};v.exports.generate=t=>{t=t||{},"length"in t||(t.length=10),"number"in t||(t.numbers=!1),"symbols"in t||(t.symbols=!1),"uppercase"in t||(t.uppercase=!0),"lowercase"in t||(t.lowercase=!0),"exclude"in t||(t.exclude="");let e="";if(t.lowercase&&(e+=N),t.uppercase&&(e+=L),t.numbers&&(e+=$),t.symbols&&(typeof t.symbols=="string"?e+=t.symbols:e+=A),!e)throw new TypeError("At least one rule must be true");let r=t.exclude.length;for(;r--;)e=e.replace(t.exclude[r],"");return F(t,e)}});var f=x((V,h)=>{var u=p(require("crypto"));h.exports.encrypt=t=>{let e=u.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),n=u.createCipheriv(t.algorithm,e,r),s=n.update(t.text);return s=Buffer.concat([s,n.final()]),s.toString(t.output)};h.exports.decrypt=t=>{let e=u.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),n=u.createDecipheriv(t.algorithm,e,r),s=n.update(Buffer.from(t.text,"hex"));return s=Buffer.concat([s,n.final()]),s.toString(t.output)};h.exports.hash=t=>{let e;return t.output==="bytes"?e=u.createHash(t.algorithm).update(String(t.text)):e=u.createHash(t.algorithm).update(String(t.text)).digest(t.output),e}});var E=p(require("path")),j=p(require("fs"));module.exports={loadEnv(t){if(typeof t!="string")throw new TypeError("filePath must be a string");let e=j.readFileSync(E.resolve(t),"utf8"),r={};for(let n of e.split(`
`)){let s=n.split(/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg);r[s[1]]=s[2]}return r},randomNum(t,e,r){if(typeof t!="number")throw new TypeError("minimum must be a number");if(typeof e!="number")throw new TypeError("maximum must be a number");r=r!=null?r:0;let n=Math.random()*(e-t+1)+t;return Math.floor(n*10**r)/10**r},randomBol(){return Math.floor(Math.random()*2)+1===1},randomStr(t){var m,i,g,b,d,w;if(typeof t!="object")throw new TypeError("options must be an object");let e=(m=t.length)!=null?m:12,r=(i=t.numbers)!=null?i:!0,n=(g=t.symbols)!=null?g:!1,s=(b=t.uppercase)!=null?b:!0,o=(d=t.lowercase)!=null?d:!0,a=(w=t.exclude)!=null?w:"";return B().generate({length:e,numbers:r,symbols:n,uppercase:s,lowercase:o,exclude:a})},spinner:class{constructor(e){this.state=0,this.states=e!=null?e:["/","-","\\","|"]}get(){return this.state>=this.states.length&&(this.state=0),this.state++,this.states[this.state-1]}},encryptStr(t){var a,c,m,i;if(typeof t!="object")throw new TypeError("options must be an object");let e=(a=t.text)!=null?a:"Javascript Moment",r=(c=t.algorithm)!=null?c:"aes-256-cbc",n=(m=t.output)!=null?m:"hex",s=(i=t.key)!=null?i:"123unsafe";return f().encrypt({text:e,algorithm:r,output:n,key:s})},decryptStr(t){var a,c,m,i;if(typeof t!="object")throw new TypeError("options must be an object");let e=(a=t.text)!=null?a:"Javascript Moment",r=(c=t.algorithm)!=null?c:"aes-256-cbc",n=(m=t.output)!=null?m:"utf8",s=(i=t.key)!=null?i:"123unsafe";return f().decrypt({text:e,algorithm:r,output:n,key:s})},hashStr(t){var o,a,c;if(typeof t!="object")throw new TypeError("options must be an object");let e=(o=t.text)!=null?o:"Javascript Moment",r=(a=t.algorithm)!=null?a:"sha256",n=(c=t.output)!=null?c:"hex";return f().hash({text:e,algorithm:r,output:n})}};
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
__export(src_exports, {
Spinner: () => Spinner,
Version: () => Version,
decryptStr: () => decryptStr,
decryptStrOptions: () => import_decryptStrOptions.default,
encryptStr: () => encryptStr,
encryptStrOptions: () => import_encryptStrOptions.default,
hashStr: () => hashStr,
hashStrOptions: () => import_hashStrOptions.default,
loadEnv: () => loadEnv,
randomBol: () => randomBol,
randomNum: () => randomNum,
randomStr: () => randomStr,
randomStrOptions: () => import_randomStrOptions.default
});
module.exports = __toCommonJS(src_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var import_randomStrOptions = __toESM(require("./types/randomStrOptions"));
var import_encryptStrOptions = __toESM(require("./types/encryptStrOptions"));
var import_decryptStrOptions = __toESM(require("./types/decryptStrOptions"));
var import_hashStrOptions = __toESM(require("./types/hashStrOptions"));
var randomString = __toESM(require("./utils/randomString"));
var cryptString = __toESM(require("./utils/cryptString"));
var import_pckg = require("./pckg.json");
const Version = import_pckg.version;
function loadEnv(file, isAsync) {
if (typeof file !== "string")
throw new TypeError("filePath must be a string");
file = path.resolve(file);
const parseContent = (content) => {
let returns = {};
for (const line of content.split("\n")) {
const keys = line.split(/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg);
returns[keys[1]] = keys[2];
}
return returns;
};
if (isAsync)
return new Promise(async (resolve, reject) => {
try {
const content = await fs.promises.readFile(file, "utf8");
return resolve(parseContent(content));
} catch (err) {
return reject(err);
}
});
else
return parseContent(fs.readFileSync(file, "utf8"));
}
function randomNum(min, max, dec) {
if (typeof min !== "number")
throw new TypeError("minimum must be a number");
if (typeof max !== "number")
throw new TypeError("maximum must be a number");
dec = dec != null ? dec : 0;
const random = Math.random() * (max - min + 1) + min;
const number = Math.floor(random * 10 ** dec) / 10 ** dec;
return number;
}
function randomBol() {
const boolean = Math.floor(Math.random() * (2 - 1 + 1)) + 1;
return boolean === 1;
}
function randomStr(options = {}) {
var _a, _b, _c, _d, _e, _f;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const length = (_a = options.length) != null ? _a : 12;
const numbers = (_b = options.numbers) != null ? _b : true;
const symbols = (_c = options.symbols) != null ? _c : false;
const uppercase = (_d = options.uppercase) != null ? _d : true;
const lowercase = (_e = options.lowercase) != null ? _e : true;
const exclude = (_f = options.exclude) != null ? _f : "";
const string = randomString.password({
length,
numbers,
symbols,
uppercase,
lowercase,
exclude
});
return string;
}
class Spinner {
/** Create a Spinner */
constructor(states) {
this.state = 0;
this.states = states != null ? states : [
"/",
"-",
"\\",
"|"
];
}
/** Get the Current State */
get() {
if (this.state >= this.states.length)
this.state = 0;
return this.states[this.state++];
}
}
function encryptStr(options = { text: "" }) {
var _a, _b, _c, _d;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "aes-256-cbc";
const output = (_c = options.output) != null ? _c : "hex";
const key = (_d = options.key) != null ? _d : "123unsafe";
const data = cryptString.encrypt({
text,
algorithm,
output,
key
});
return data;
}
function decryptStr(options = { text: "" }) {
var _a, _b, _c, _d;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "aes-256-cbc";
const output = (_c = options.output) != null ? _c : "utf8";
const key = (_d = options.key) != null ? _d : "123unsafe";
const data = cryptString.decrypt({
text,
algorithm,
output,
key
});
return data;
}
function hashStr(options = { text: "" }) {
var _a, _b, _c;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "sha256";
const output = (_c = options.output) != null ? _c : "hex";
const data = cryptString.hash({
text,
algorithm,
output
});
return data;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Spinner,
Version,
decryptStr,
decryptStrOptions,
encryptStr,
encryptStrOptions,
hashStr,
hashStrOptions,
loadEnv,
randomBol,
randomNum,
randomStr,
randomStrOptions
});

@@ -1,1 +0,8 @@

export {};
/// <reference types="node" />
import * as crypto from "crypto";
import encryptStrOptions from "../types/encryptStrOptions";
import decryptStrOptions from "../types/decryptStrOptions";
import hashStrOptions from "../types/hashStrOptions";
export declare const encrypt: (options: encryptStrOptions) => string;
export declare const decrypt: (options: decryptStrOptions) => string;
export declare const hash: (options: hashStrOptions) => string | crypto.Hash;

@@ -1,1 +0,66 @@

var i=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,n=Object.prototype.hasOwnProperty;var y=(t,r,a,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of o(r))!n.call(t,e)&&e!==a&&s(t,e,{get:()=>r[e],enumerable:!(p=h(r,e))||p.enumerable});return t};var f=(t,r,a)=>(a=t!=null?i(u(t)):{},y(r||!t||!t.__esModule?s(a,"default",{value:t,enumerable:!0}):a,t));var c=f(require("crypto"));module.exports.encrypt=t=>{let r=c.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),a=Buffer.alloc(16,0),p=c.createCipheriv(t.algorithm,r,a),e=p.update(t.text);return e=Buffer.concat([e,p.final()]),e.toString(t.output)};module.exports.decrypt=t=>{let r=c.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),a=Buffer.alloc(16,0),p=c.createDecipheriv(t.algorithm,r,a),e=p.update(Buffer.from(t.text,"hex"));return e=Buffer.concat([e,p.final()]),e.toString(t.output)};module.exports.hash=t=>{let r;return t.output==="bytes"?r=c.createHash(t.algorithm).update(String(t.text)):r=c.createHash(t.algorithm).update(String(t.text)).digest(t.output),r};
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var cryptString_exports = {};
__export(cryptString_exports, {
decrypt: () => decrypt,
encrypt: () => encrypt,
hash: () => hash
});
module.exports = __toCommonJS(cryptString_exports);
var crypto = __toESM(require("crypto"));
const encrypt = (options) => {
const key = crypto.createHash("sha256").update(String(options.key)).digest("base64").substring(0, 32);
const iv = Buffer.alloc(16, 0);
const enCipher = crypto.createCipheriv(options.algorithm, key, iv);
let encryptedData = enCipher.update(options.text);
encryptedData = Buffer.concat([encryptedData, enCipher.final()]);
return encryptedData.toString(options.output);
};
const decrypt = (options) => {
const key = crypto.createHash("sha256").update(String(options.key)).digest("base64").substring(0, 32);
const iv = Buffer.alloc(16, 0);
const deCipher = crypto.createDecipheriv(options.algorithm, key, iv);
let decryptedData = deCipher.update(Buffer.from(options.text, "hex"));
decryptedData = Buffer.concat([decryptedData, deCipher.final()]);
return decryptedData.toString(options.output);
};
const hash = (options) => {
let hash2;
if (options.output === "bytes")
hash2 = crypto.createHash(options.algorithm).update(String(options.text));
else
hash2 = crypto.createHash(options.algorithm).update(String(options.text)).digest(options.output);
return hash2;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
decrypt,
encrypt,
hash
});

@@ -1,1 +0,2 @@

export {};
import randomStrOptions from "../types/randomStrOptions";
export declare const password: (options: randomStrOptions) => string;

@@ -1,1 +0,107 @@

var d=Object.create;var c=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var w=(e,r,l,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of g(r))!h.call(e,t)&&t!==l&&c(e,t,{get:()=>r[t],enumerable:!(n=b(r,t))||n.enumerable});return e};var i=(e,r,l)=>(l=e!=null?d(y(e)):{},w(r||!e||!e.__esModule?c(l,"default",{value:e,enumerable:!0}):l,e));var f=i(require("crypto")),s,u,m=()=>{(s===void 0||s>=u.length)&&(s=0,u=f.randomBytes(256));let e=u[s];return s+=1,e},o=e=>{let r=m();for(;r>=256-256%e;)r=m();return r%e},x="abcdefghijklmnopqrstuvwxyz",B="ABCDEFGHIJKLMNOPQRSTUVWXYZ",O="0123456789",S='!@#$%^&*()+_-=}{[]|:;"/?.><,`~',p=(e,r)=>{let l=e.length,n=r.length,t="";for(let a=0;a<l;a++)t+=r[o(n)];return t};module.exports.generate=e=>{e=e||{},"length"in e||(e.length=10),"number"in e||(e.numbers=!1),"symbols"in e||(e.symbols=!1),"uppercase"in e||(e.uppercase=!0),"lowercase"in e||(e.lowercase=!0),"exclude"in e||(e.exclude="");let r="";if(e.lowercase&&(r+=x),e.uppercase&&(r+=B),e.numbers&&(r+=O),e.symbols&&(typeof e.symbols=="string"?r+=e.symbols:r+=S),!r)throw new TypeError("At least one rule must be true");let l=e.exclude.length;for(;l--;)r=r.replace(e.exclude[l],"");return p(e,r)};
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var randomString_exports = {};
__export(randomString_exports, {
password: () => password
});
module.exports = __toCommonJS(randomString_exports);
var crypto = __toESM(require("crypto"));
let randomIndex;
let randomBytes;
const getNextRandomValue = () => {
if (randomIndex === void 0 || randomIndex >= randomBytes.length) {
randomIndex = 0;
randomBytes = crypto.randomBytes(256);
}
const result = randomBytes[randomIndex];
randomIndex += 1;
return result;
};
const randomNumber = (max) => {
let rand = getNextRandomValue();
while (rand >= 256 - 256 % max)
rand = getNextRandomValue();
return rand % max;
};
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbers = "0123456789";
const symbols = '!@#$%^&*()+_-=}{[]|:;"/?.><,`~';
const generate = (options, pool) => {
var _a;
const optionsLength = (_a = options.length) != null ? _a : 12;
const poolLength = pool.length;
let password2 = "";
for (let i = 0; i < optionsLength; i++)
password2 += pool[randomNumber(poolLength)];
return password2;
};
const password = (options) => {
var _a, _b;
options = options || {};
if (!("length" in options))
options.length = 10;
if (!("number" in options))
options.numbers = false;
if (!("symbols" in options))
options.symbols = false;
if (!("uppercase" in options))
options.uppercase = true;
if (!("lowercase" in options))
options.lowercase = true;
if (!("exclude" in options))
options.exclude = "";
let pool = "";
if (options.lowercase)
pool += lowercase;
if (options.uppercase)
pool += uppercase;
if (options.numbers)
pool += numbers;
if (options.symbols) {
if (typeof options.symbols === "string")
pool += options.symbols;
else
pool += symbols;
}
if (!pool) {
throw new TypeError("At least one rule must be true");
}
;
let i = (_b = (_a = options.exclude) == null ? void 0 : _a.length) != null ? _b : 0;
while (i--) {
pool = pool.replace(options.exclude[i], "");
}
const password2 = generate(options, pool);
return password2;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
password
});
/// <reference types="node" />
import { Hash } from "crypto";
import randomStrOptions from "./interfaces/randomStrOptions";
import encryptStrOptions from "./interfaces/encryptStrOptions";
import decryptStrOptions from "./interfaces/decryptStrOptions";
import hashStrOptions from "./interfaces/hashStrOptions";
declare const _default: {
/** Load an Env File to JSON */
loadEnv(filePath: string): {
[key: string]: string;
};
/** Generate a Random Number */
randomNum(min: number, max: number, dec?: number): number;
/** Generate a Random Boolean */
randomBol(): boolean;
/** Generate a Random String */
randomStr(options: randomStrOptions): string;
/** Generate a Text Spinner */
spinner: {
new (states?: string[]): {
states: string[];
state: number;
/** Get the Current State */
get(): string;
};
};
/** Encrypt a String */
encryptStr(options: encryptStrOptions): string;
/** Decrypt a String */
decryptStr(options: decryptStrOptions): string;
/** Hash a String */
hashStr(options: hashStrOptions): string | Hash;
};
export = _default;
import randomStrOptions from "./types/randomStrOptions";
import encryptStrOptions from "./types/encryptStrOptions";
import decryptStrOptions from "./types/decryptStrOptions";
import hashStrOptions from "./types/hashStrOptions";
export declare const Version: string;
export { randomStrOptions, encryptStrOptions, decryptStrOptions, hashStrOptions };
/**
* Load an Env File as Object
* @since 1.0.0
*/ export declare function loadEnv<F, A extends boolean | undefined>(
/** The path to the Env file */ file: string,
/** Whether to load the File Async */ isAsync: boolean): A extends true ? Promise<Record<string, string>> : Record<string, string>;
/**
* Generate a Random Number
* @since 1.0.0
*/ export declare function randomNum(
/** The Minimum Number */ min: number,
/** The Maximum Number */ max: number,
/**
* The Decimal Places to Generate
* @default 0
*/ dec?: number): number;
/**
* Generate a Random Boolean
* @since 1.0.1
*/ export declare function randomBol(): boolean;
/**
* Generate a Random String
* @since 1.0.0
*/ export declare function randomStr(options?: randomStrOptions): string;
/**
* Generate a Text Spinner
* @since 1.0.2
*/ export declare class Spinner {
states: string[];
state: number;
/** Create a Spinner */
constructor(
/** The States */ states?: string[]);
/** Get the Current State */
get(): string;
}
/**
* Encrypt a String
* @since 1.0.3
*/ export declare function encryptStr(options?: encryptStrOptions): string;
/**
* Decrypt a String
* @since 1.0.3
*/ export declare function decryptStr(options?: decryptStrOptions): string;
/**
* Hash a String
* @since 1.0.4
*/ export declare function hashStr<T extends hashStrOptions>(options?: hashStrOptions): T['output'] extends 'bytes' ? Hash : string;

@@ -1,2 +0,147 @@

var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);import*as x from"crypto";var k=f((N,O)=>{var l,y,S=()=>{(l===void 0||l>=y.length)&&(l=0,y=x.randomBytes(256));let t=y[l];return l+=1,t},j=t=>{let e=S();for(;e>=256-256%t;)e=S();return e%t},T="abcdefghijklmnopqrstuvwxyz",H="ABCDEFGHIJKLMNOPQRSTUVWXYZ",M="0123456789",q='!@#$%^&*()+_-=}{[]|:;"/?.><,`~',C=(t,e)=>{let r=t.length,n=e.length,s="";for(let o=0;o<r;o++)s+=e[j(n)];return s};O.exports.generate=t=>{t=t||{},"length"in t||(t.length=10),"number"in t||(t.numbers=!1),"symbols"in t||(t.symbols=!1),"uppercase"in t||(t.uppercase=!0),"lowercase"in t||(t.lowercase=!0),"exclude"in t||(t.exclude="");let e="";if(t.lowercase&&(e+=T),t.uppercase&&(e+=H),t.numbers&&(e+=M),t.symbols&&(typeof t.symbols=="string"?e+=t.symbols:e+=q),!e)throw new TypeError("At least one rule must be true");let r=t.exclude.length;for(;r--;)e=e.replace(t.exclude[r],"");return C(t,e)}});import*as u from"crypto";var h=f((L,p)=>{p.exports.encrypt=t=>{let e=u.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),n=u.createCipheriv(t.algorithm,e,r),s=n.update(t.text);return s=Buffer.concat([s,n.final()]),s.toString(t.output)};p.exports.decrypt=t=>{let e=u.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),n=u.createDecipheriv(t.algorithm,e,r),s=n.update(Buffer.from(t.text,"hex"));return s=Buffer.concat([s,n.final()]),s.toString(t.output)};p.exports.hash=t=>{let e;return t.output==="bytes"?e=u.createHash(t.algorithm).update(String(t.text)):e=u.createHash(t.algorithm).update(String(t.text)).digest(t.output),e}});import*as v from"path";import*as B from"fs";var D=f((A,E)=>{E.exports={loadEnv(t){if(typeof t!="string")throw new TypeError("filePath must be a string");let e=B.readFileSync(v.resolve(t),"utf8"),r={};for(let n of e.split(`
`)){let s=n.split(/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg);r[s[1]]=s[2]}return r},randomNum(t,e,r){if(typeof t!="number")throw new TypeError("minimum must be a number");if(typeof e!="number")throw new TypeError("maximum must be a number");r=r!=null?r:0;let n=Math.random()*(e-t+1)+t;return Math.floor(n*10**r)/10**r},randomBol(){return Math.floor(Math.random()*2)+1===1},randomStr(t){var m,i,g,b,d,w;if(typeof t!="object")throw new TypeError("options must be an object");let e=(m=t.length)!=null?m:12,r=(i=t.numbers)!=null?i:!0,n=(g=t.symbols)!=null?g:!1,s=(b=t.uppercase)!=null?b:!0,o=(d=t.lowercase)!=null?d:!0,a=(w=t.exclude)!=null?w:"";return k().generate({length:e,numbers:r,symbols:n,uppercase:s,lowercase:o,exclude:a})},spinner:class{constructor(e){this.state=0,this.states=e!=null?e:["/","-","\\","|"]}get(){return this.state>=this.states.length&&(this.state=0),this.state++,this.states[this.state-1]}},encryptStr(t){var a,c,m,i;if(typeof t!="object")throw new TypeError("options must be an object");let e=(a=t.text)!=null?a:"Javascript Moment",r=(c=t.algorithm)!=null?c:"aes-256-cbc",n=(m=t.output)!=null?m:"hex",s=(i=t.key)!=null?i:"123unsafe";return h().encrypt({text:e,algorithm:r,output:n,key:s})},decryptStr(t){var a,c,m,i;if(typeof t!="object")throw new TypeError("options must be an object");let e=(a=t.text)!=null?a:"Javascript Moment",r=(c=t.algorithm)!=null?c:"aes-256-cbc",n=(m=t.output)!=null?m:"utf8",s=(i=t.key)!=null?i:"123unsafe";return h().decrypt({text:e,algorithm:r,output:n,key:s})},hashStr(t){var o,a,c;if(typeof t!="object")throw new TypeError("options must be an object");let e=(o=t.text)!=null?o:"Javascript Moment",r=(a=t.algorithm)!=null?a:"sha256",n=(c=t.output)!=null?c:"hex";return h().hash({text:e,algorithm:r,output:n})}}});export default D();
import * as path from "path";
import * as fs from "fs";
import randomStrOptions from "./types/randomStrOptions";
import encryptStrOptions from "./types/encryptStrOptions";
import decryptStrOptions from "./types/decryptStrOptions";
import hashStrOptions from "./types/hashStrOptions";
import * as randomString from "./utils/randomString";
import * as cryptString from "./utils/cryptString";
import { version } from "./pckg.json";
const Version = version;
function loadEnv(file, isAsync) {
if (typeof file !== "string")
throw new TypeError("filePath must be a string");
file = path.resolve(file);
const parseContent = (content) => {
let returns = {};
for (const line of content.split("\n")) {
const keys = line.split(/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg);
returns[keys[1]] = keys[2];
}
return returns;
};
if (isAsync)
return new Promise(async (resolve, reject) => {
try {
const content = await fs.promises.readFile(file, "utf8");
return resolve(parseContent(content));
} catch (err) {
return reject(err);
}
});
else
return parseContent(fs.readFileSync(file, "utf8"));
}
function randomNum(min, max, dec) {
if (typeof min !== "number")
throw new TypeError("minimum must be a number");
if (typeof max !== "number")
throw new TypeError("maximum must be a number");
dec = dec != null ? dec : 0;
const random = Math.random() * (max - min + 1) + min;
const number = Math.floor(random * 10 ** dec) / 10 ** dec;
return number;
}
function randomBol() {
const boolean = Math.floor(Math.random() * (2 - 1 + 1)) + 1;
return boolean === 1;
}
function randomStr(options = {}) {
var _a, _b, _c, _d, _e, _f;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const length = (_a = options.length) != null ? _a : 12;
const numbers = (_b = options.numbers) != null ? _b : true;
const symbols = (_c = options.symbols) != null ? _c : false;
const uppercase = (_d = options.uppercase) != null ? _d : true;
const lowercase = (_e = options.lowercase) != null ? _e : true;
const exclude = (_f = options.exclude) != null ? _f : "";
const string = randomString.password({
length,
numbers,
symbols,
uppercase,
lowercase,
exclude
});
return string;
}
class Spinner {
/** Create a Spinner */
constructor(states) {
this.state = 0;
this.states = states != null ? states : [
"/",
"-",
"\\",
"|"
];
}
/** Get the Current State */
get() {
if (this.state >= this.states.length)
this.state = 0;
return this.states[this.state++];
}
}
function encryptStr(options = { text: "" }) {
var _a, _b, _c, _d;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "aes-256-cbc";
const output = (_c = options.output) != null ? _c : "hex";
const key = (_d = options.key) != null ? _d : "123unsafe";
const data = cryptString.encrypt({
text,
algorithm,
output,
key
});
return data;
}
function decryptStr(options = { text: "" }) {
var _a, _b, _c, _d;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "aes-256-cbc";
const output = (_c = options.output) != null ? _c : "utf8";
const key = (_d = options.key) != null ? _d : "123unsafe";
const data = cryptString.decrypt({
text,
algorithm,
output,
key
});
return data;
}
function hashStr(options = { text: "" }) {
var _a, _b, _c;
if (typeof options !== "object")
throw new TypeError("options must be an object");
const text = (_a = options.text) != null ? _a : "Javascript Moment";
const algorithm = (_b = options.algorithm) != null ? _b : "sha256";
const output = (_c = options.output) != null ? _c : "hex";
const data = cryptString.hash({
text,
algorithm,
output
});
return data;
}
export {
Spinner,
Version,
decryptStr,
decryptStrOptions,
encryptStr,
encryptStrOptions,
hashStr,
hashStrOptions,
loadEnv,
randomBol,
randomNum,
randomStr,
randomStrOptions
};

@@ -1,1 +0,8 @@

export {};
/// <reference types="node" />
import * as crypto from "crypto";
import encryptStrOptions from "../types/encryptStrOptions";
import decryptStrOptions from "../types/decryptStrOptions";
import hashStrOptions from "../types/hashStrOptions";
export declare const encrypt: (options: encryptStrOptions) => string;
export declare const decrypt: (options: decryptStrOptions) => string;
export declare const hash: (options: hashStrOptions) => string | crypto.Hash;

@@ -1,1 +0,30 @@

var i=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports);import*as e from"crypto";var h=i((u,p)=>{p.exports.encrypt=t=>{let r=e.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),s=Buffer.alloc(16,0),c=e.createCipheriv(t.algorithm,r,s),a=c.update(t.text);return a=Buffer.concat([a,c.final()]),a.toString(t.output)};p.exports.decrypt=t=>{let r=e.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),s=Buffer.alloc(16,0),c=e.createDecipheriv(t.algorithm,r,s),a=c.update(Buffer.from(t.text,"hex"));return a=Buffer.concat([a,c.final()]),a.toString(t.output)};p.exports.hash=t=>{let r;return t.output==="bytes"?r=e.createHash(t.algorithm).update(String(t.text)):r=e.createHash(t.algorithm).update(String(t.text)).digest(t.output),r}});export default h();
import * as crypto from "crypto";
const encrypt = (options) => {
const key = crypto.createHash("sha256").update(String(options.key)).digest("base64").substring(0, 32);
const iv = Buffer.alloc(16, 0);
const enCipher = crypto.createCipheriv(options.algorithm, key, iv);
let encryptedData = enCipher.update(options.text);
encryptedData = Buffer.concat([encryptedData, enCipher.final()]);
return encryptedData.toString(options.output);
};
const decrypt = (options) => {
const key = crypto.createHash("sha256").update(String(options.key)).digest("base64").substring(0, 32);
const iv = Buffer.alloc(16, 0);
const deCipher = crypto.createDecipheriv(options.algorithm, key, iv);
let decryptedData = deCipher.update(Buffer.from(options.text, "hex"));
decryptedData = Buffer.concat([decryptedData, deCipher.final()]);
return decryptedData.toString(options.output);
};
const hash = (options) => {
let hash2;
if (options.output === "bytes")
hash2 = crypto.createHash(options.algorithm).update(String(options.text));
else
hash2 = crypto.createHash(options.algorithm).update(String(options.text)).digest(options.output);
return hash2;
};
export {
decrypt,
encrypt,
hash
};

@@ -1,1 +0,2 @@

export {};
import randomStrOptions from "../types/randomStrOptions";
export declare const password: (options: randomStrOptions) => string;

@@ -1,1 +0,73 @@

var d=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);import*as m from"crypto";var o=d((B,f)=>{var l,n,c=()=>{(l===void 0||l>=n.length)&&(l=0,n=m.randomBytes(256));let e=n[l];return l+=1,e},b=e=>{let r=c();for(;r>=256-256%e;)r=c();return r%e},g="abcdefghijklmnopqrstuvwxyz",y="ABCDEFGHIJKLMNOPQRSTUVWXYZ",h="0123456789",w='!@#$%^&*()+_-=}{[]|:;"/?.><,`~',i=(e,r)=>{let t=e.length,s=r.length,u="";for(let a=0;a<t;a++)u+=r[b(s)];return u};f.exports.generate=e=>{e=e||{},"length"in e||(e.length=10),"number"in e||(e.numbers=!1),"symbols"in e||(e.symbols=!1),"uppercase"in e||(e.uppercase=!0),"lowercase"in e||(e.lowercase=!0),"exclude"in e||(e.exclude="");let r="";if(e.lowercase&&(r+=g),e.uppercase&&(r+=y),e.numbers&&(r+=h),e.symbols&&(typeof e.symbols=="string"?r+=e.symbols:r+=w),!r)throw new TypeError("At least one rule must be true");let t=e.exclude.length;for(;t--;)r=r.replace(e.exclude[t],"");return i(e,r)}});export default o();
import * as crypto from "crypto";
let randomIndex;
let randomBytes;
const getNextRandomValue = () => {
if (randomIndex === void 0 || randomIndex >= randomBytes.length) {
randomIndex = 0;
randomBytes = crypto.randomBytes(256);
}
const result = randomBytes[randomIndex];
randomIndex += 1;
return result;
};
const randomNumber = (max) => {
let rand = getNextRandomValue();
while (rand >= 256 - 256 % max)
rand = getNextRandomValue();
return rand % max;
};
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbers = "0123456789";
const symbols = '!@#$%^&*()+_-=}{[]|:;"/?.><,`~';
const generate = (options, pool) => {
var _a;
const optionsLength = (_a = options.length) != null ? _a : 12;
const poolLength = pool.length;
let password2 = "";
for (let i = 0; i < optionsLength; i++)
password2 += pool[randomNumber(poolLength)];
return password2;
};
const password = (options) => {
var _a, _b;
options = options || {};
if (!("length" in options))
options.length = 10;
if (!("number" in options))
options.numbers = false;
if (!("symbols" in options))
options.symbols = false;
if (!("uppercase" in options))
options.uppercase = true;
if (!("lowercase" in options))
options.lowercase = true;
if (!("exclude" in options))
options.exclude = "";
let pool = "";
if (options.lowercase)
pool += lowercase;
if (options.uppercase)
pool += uppercase;
if (options.numbers)
pool += numbers;
if (options.symbols) {
if (typeof options.symbols === "string")
pool += options.symbols;
else
pool += symbols;
}
if (!pool) {
throw new TypeError("At least one rule must be true");
}
;
let i = (_b = (_a = options.exclude) == null ? void 0 : _a.length) != null ? _b : 0;
while (i--) {
pool = pool.replace(options.exclude[i], "");
}
const password2 = generate(options, pool);
return password2;
};
export {
password
};
{
"name": "rjutils-collection",
"version": "1.2.0",
"version": "1.2.1",
"description": "Easy and Lightweight Utilities",

@@ -8,3 +8,4 @@ "module": "lib/esm/index.js",

"scripts": {
"build": "rm -rf lib && tsc && esbuild `find src \\( -name '*.ts' -o -name '*.tsx' \\)` --platform='node' --minify --bundle --ignore-annotations --format='cjs' --outdir='lib/cjs' && esbuild `find src \\( -name '*.ts' -o -name '*.tsx' \\)` --platform='node' --minify --bundle --ignore-annotations --format='esm' --outdir='lib/esm' && cp -r lib/typings/* lib/cjs && cp -r lib/typings/* lib/esm && rm -rf lib/typings"
"build": "rm -rf lib && tsc && esbuild `find src \\( -name '*.ts' -o -name '*.tsx' \\)` --platform='node' --ignore-annotations --format='cjs' --outdir='lib/cjs' && esbuild `find src \\( -name '*.ts' -o -name '*.tsx' \\)` --platform='node' --ignore-annotations --format='esm' --outdir='lib/esm' && cp -r lib/typings/* lib/cjs && cp -r lib/typings/* lib/esm && rm -rf lib/typings && cp package.json lib/cjs/pckg.json && cp package.json lib/esm/pckg.json",
"test": "yarn build && node test"
}, "repository": {

@@ -17,3 +18,9 @@ "type": "git",

"file",
"sync"
"sync",
"async",
"crypto",
"hashing",
"hash",
"password",
"binary"
], "author": "0x4096 (Robert Jansen)",

@@ -27,4 +34,5 @@ "license": "MIT",

"esbuild": "^0.17.2",
"rjutils-collection": "link:.",
"typescript": "^4.9.4"
}
}

@@ -21,9 +21,10 @@ <h1 align="center">Welcome to rjutils-collection 👋</h1>

```sh
# NPM
npm i rjutils-collection
```
or
# Yarn
yarn add rjutils-collection
```sh
yarn add rjutils-collection
# pNPM
pnpm add rjutils-collection
```

@@ -33,5 +34,5 @@

Loading an env File as json
Loading an env File as object
```js
const path = require('node:path')
const path = require('path')
const utils = require('rjutils-collection')

@@ -38,0 +39,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc