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.1.1 to 1.1.2

18

lib/index.d.ts

@@ -0,1 +1,3 @@

/// <reference types="node" />
import { Hash } from "crypto";
import randomStrOptions from "./interfaces/randomStrOptions";

@@ -7,3 +9,5 @@ import encryptStrOptions from "./interfaces/encryptStrOptions";

/** Load an Env File to JSON */
loadEnv(filePath: string): {};
loadEnv(filePath: string): {
[key: string]: string;
};
/** Generate a Random Number */

@@ -14,8 +18,9 @@ randomNum(min: number, max: number, dec?: number): number;

/** Generate a Random String */
randomStr(options: randomStrOptions): any;
randomStr(options: randomStrOptions): string;
/** Generate a Text Spinner */
spinner: {
new (): {
new (states?: string[]): {
states: string[];
state: number;
/** Get the Current State */
get(): string;

@@ -25,9 +30,8 @@ };

/** Encrypt a String */
encryptStr(options: encryptStrOptions): any;
encryptStr(options: encryptStrOptions): string;
/** Decrypt a String */
decryptStr(options: decryptStrOptions): any;
decryptStr(options: decryptStrOptions): string;
/** Hash a String */
hashStr(options: hashStrOptions): any;
hashStr(options: hashStrOptions): string | Hash;
};
export = _default;
//# sourceMappingURL=index.d.ts.map

@@ -1,133 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
module.exports = {
/** Load an Env File to JSON */
loadEnv(
/** The path to the Env file */ filePath) {
if (typeof filePath !== 'string')
throw new TypeError('filePath must be a string');
const content = fs.readFileSync(path.resolve(filePath), 'utf8');
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;
},
/** Generate a Random Number */
randomNum(
/** The Minimum Number */ min,
/** The Maximum Number */ max,
/**
* The Decimal Places to Generate
* @default 0
*/ 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 ?? 0;
const random = Math.random() * (max - min + 1) + min;
const number = Math.floor(random * (10 ** dec)) / (10 ** dec);
return number;
},
/** Generate a Random Boolean */
randomBol() {
const boolean = Math.floor(Math.random() * (2 - 1 + 1)) + 1;
return (boolean === 1);
},
/** Generate a Random String */
randomStr(options) {
if (typeof options !== 'object')
throw new TypeError('options must be an object');
const length = options.length ?? 12;
const numbers = options.numbers ?? true;
const symbols = options.symbols ?? false;
const uppercase = options.uppercase ?? true;
const lowercase = options.lowercase ?? true;
const exclude = options.exclude ?? '';
const string = require('./utils/randomString').generate({
length, numbers, symbols, uppercase, lowercase, exclude
});
return string;
},
/** Generate a Text Spinner */
spinner: class spinner {
constructor() {
this.state = 0;
this.states = [
'/', '-',
'\\', '|'
];
}
get() {
if (this.state >= 4)
this.state = 0;
this.state++;
return this.states[this.state - 1];
}
},
/** Encrypt a String */
encryptStr(options) {
if (typeof options !== 'object')
throw new TypeError('options must be an object');
const text = options.text ?? 'Javascript Moment';
const algorithm = options.algorithm ?? 'aes-256-cbc';
const output = options.output ?? 'hex';
const key = options.key ?? '123unsafe';
const data = require('./utils/cryptString').encrypt({
text, algorithm, output, key
});
return data;
},
/** Decrypt a String */
decryptStr(options) {
if (typeof options !== 'object')
throw new TypeError('options must be an object');
const text = options.text ?? 'Javascript Moment';
const algorithm = options.algorithm ?? 'aes-256-cbc';
const output = options.output ?? 'utf8';
const key = options.key ?? '123unsafe';
const data = require('./utils/cryptString').decrypt({
text, algorithm, output, key
});
return data;
},
/** Hash a String */
hashStr(options) {
if (typeof options !== 'object')
throw new TypeError('options must be an object');
const text = options.text ?? 'Javascript Moment';
const algorithm = options.algorithm ?? 'sha256';
const output = options.output ?? 'hex';
const data = require('./utils/cryptString').hash({
text, algorithm, output
});
return data;
},
};
//# sourceMappingURL=index.js.map
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var s=Object.getOwnPropertyDescriptor(e,r);s&&!("get"in s?!e.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,s)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&__createBinding(e,t,r);return __setModuleDefault(e,t),e};const path=__importStar(require("path")),fs=__importStar(require("fs"));module.exports={loadEnv(t){if("string"!=typeof t)throw new TypeError("filePath must be a string");const e=fs.readFileSync(path.resolve(t),"utf8");let r={};for(const t of e.split("\n")){const e=t.split(/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm);r[e[1]]=e[2]}return r},randomNum(t,e,r){if("number"!=typeof t)throw new TypeError("minimum must be a number");if("number"!=typeof e)throw new TypeError("maximum must be a number");r=r??0;const o=Math.random()*(e-t+1)+t;return Math.floor(o*10**r)/10**r},randomBol:()=>1===Math.floor(2*Math.random())+1,randomStr(t){if("object"!=typeof t)throw new TypeError("options must be an object");const e=t.length??12,r=t.numbers??!0,o=t.symbols??!1,s=t.uppercase??!0,n=t.lowercase??!0,i=t.exclude??"";return require("./utils/randomString").generate({length:e,numbers:r,symbols:o,uppercase:s,lowercase:n,exclude:i})},spinner:class{constructor(t){this.state=0,this.states=t??["/","-","\\","|"]}get(){return this.state>=this.states.length&&(this.state=0),this.state++,this.states[this.state-1]}},encryptStr(t){if("object"!=typeof t)throw new TypeError("options must be an object");const e=t.text??"Javascript Moment",r=t.algorithm??"aes-256-cbc",o=t.output??"hex",s=t.key??"123unsafe";return require("./utils/cryptString").encrypt({text:e,algorithm:r,output:o,key:s})},decryptStr(t){if("object"!=typeof t)throw new TypeError("options must be an object");const e=t.text??"Javascript Moment",r=t.algorithm??"aes-256-cbc",o=t.output??"utf8",s=t.key??"123unsafe";return require("./utils/cryptString").decrypt({text:e,algorithm:r,output:o,key:s})},hashStr(t){if("object"!=typeof t)throw new TypeError("options must be an object");const e=t.text??"Javascript Moment",r=t.algorithm??"sha256",o=t.output??"hex";return require("./utils/cryptString").hash({text:e,algorithm:r,output:o})}};

@@ -17,2 +17,1 @@ /// <reference types="node" />

}
//# sourceMappingURL=decryptStrOptions.d.ts.map

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=decryptStrOptions.js.map
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});

@@ -17,2 +17,1 @@ /// <reference types="node" />

}
//# sourceMappingURL=encryptStrOptions.d.ts.map

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=encryptStrOptions.js.map
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});

@@ -14,2 +14,1 @@ /// <reference types="node" />

}
//# sourceMappingURL=hashStrOptions.d.ts.map

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=hashStrOptions.js.map
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});

@@ -27,2 +27,1 @@ export default interface randomStrOptions {

}
//# sourceMappingURL=randomStrOptions.d.ts.map

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=randomStrOptions.js.map
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
export {};
//# sourceMappingURL=cryptString.d.ts.map

@@ -1,51 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = __importStar(require("crypto"));
module.exports.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);
};
module.exports.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);
};
module.exports.hash = (options) => {
let hash;
if (options.output === 'bytes')
hash = crypto.createHash(options.algorithm).update(String(options.text));
else
hash = crypto.createHash(options.algorithm).update(String(options.text)).digest(options.output);
return hash;
};
//# sourceMappingURL=cryptString.js.map
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,o){void 0===o&&(o=r);var a=Object.getOwnPropertyDescriptor(e,r);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,o,a)}:function(t,e,r,o){void 0===o&&(o=r),t[o]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&__createBinding(e,t,r);return __setModuleDefault(e,t),e};Object.defineProperty(exports,"__esModule",{value:!0});const crypto=__importStar(require("crypto"));module.exports.encrypt=t=>{const e=crypto.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),o=crypto.createCipheriv(t.algorithm,e,r);let a=o.update(t.text);return a=Buffer.concat([a,o.final()]),a.toString(t.output)},module.exports.decrypt=t=>{const e=crypto.createHash("sha256").update(String(t.key)).digest("base64").substring(0,32),r=Buffer.alloc(16,0),o=crypto.createDecipheriv(t.algorithm,e,r);let a=o.update(Buffer.from(t.text,"hex"));return a=Buffer.concat([a,o.final()]),a.toString(t.output)},module.exports.hash=t=>{let e;return e="bytes"===t.output?crypto.createHash(t.algorithm).update(String(t.text)):crypto.createHash(t.algorithm).update(String(t.text)).digest(t.output),e};
export {};
//# sourceMappingURL=randomString.d.ts.map

@@ -1,94 +0,1 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = __importStar(require("crypto"));
let randomIndex;
let randomBytes;
const getNextRandomValue = () => {
if (randomIndex === undefined || 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) => {
const optionsLength = options.length;
const poolLength = pool.length;
let password = '';
for (let i = 0; i < optionsLength; i++)
password += pool[randomNumber(poolLength)];
return password;
};
module.exports.generate = (options) => {
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 = options.exclude.length;
while (i--) {
pool = pool.replace(options.exclude[i], '');
}
const password = generate(options, pool);
return password;
};
//# sourceMappingURL=randomString.js.map
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0});const crypto=__importStar(require("crypto"));let randomIndex,randomBytes;const getNextRandomValue=()=>{(void 0===randomIndex||randomIndex>=randomBytes.length)&&(randomIndex=0,randomBytes=crypto.randomBytes(256));const e=randomBytes[randomIndex];return randomIndex+=1,e},randomNumber=e=>{let t=getNextRandomValue();for(;t>=256-256%e;)t=getNextRandomValue();return t%e},lowercase="abcdefghijklmnopqrstuvwxyz",uppercase="ABCDEFGHIJKLMNOPQRSTUVWXYZ",numbers="0123456789",symbols='!@#$%^&*()+_-=}{[]|:;"/?.><,`~',generate=(e,t)=>{const r=e.length,n=t.length;let o="";for(let e=0;e<r;e++)o+=t[randomNumber(n)];return o};module.exports.generate=e=>{"length"in(e=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 t="";if(e.lowercase&&(t+=lowercase),e.uppercase&&(t+=uppercase),e.numbers&&(t+=numbers),e.symbols&&("string"==typeof e.symbols?t+=e.symbols:t+=symbols),!t)throw new TypeError("At least one rule must be true");let r=e.exclude.length;for(;r--;)t=t.replace(e.exclude[r],"");return generate(e,t)};
{
"name": "rjutils-collection",
"version": "1.1.1",
"version": "1.1.2",
"description": "Easy and Lightweight Utilities",
"main": "lib/index.js",
"scripts": {
"build": "rm -r lib && tsc --pretty false"
"build": "rm -r lib && tsc --pretty false && uglifyjs-folder ./lib -e -x .js -o lib > /dev/null"
}, "repository": {

@@ -23,4 +23,5 @@ "type": "git",

"@types/node": "^18.11.18",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"uglifyjs-folder": "^3.2.0"
}
}

@@ -118,3 +118,3 @@ <h1 align="center">Welcome to rjutils-collection 👋</h1>

Copyright © 2022 [0x4096](https://github.com/rotvproHD).<br />
Copyright © 2023 [0x4096](https://github.com/rotvproHD).<br />
This project is MIT licensed.

Sorry, the diff of this file is not supported yet

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