Socket
Socket
Sign inDemoInstall

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.0.2 to 1.0.3

src/utils/cryptString.js

2

package.json
{
"name": "rjutils-collection",
"version": "1.0.2",
"version": "1.0.3",
"description": "Easy and Lightweight Utilities",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -1,85 +0,121 @@

const path = require('node:path')
const fs = require('node:fs')
const path = require('path')
const fs = require('fs')
module.exports = {
/**
* Load an Env File
*
* @param {String} filePath The path to the Env file
*/
loadEnv(filePath) {
if (typeof filePath !== 'string') throw new TypeError('filePath must be a string')
/**
* Load an Env File
*
* @param {String} filePath The path to the Env file
*/
loadEnv(filePath) {
if (typeof filePath !== 'string') throw new TypeError('filePath must be a string')
const content = fs.readFileSync(path.resolve(filePath), 'utf8')
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
},
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
*
* @param {Number} min The Minimum Number
* @param {Number} max The Maximum Number
*/
randomNum(min, max) {
if (typeof min !== 'number') throw new TypeError('minimum must be a number')
if (typeof max !== 'number') throw new TypeError('maximum must be a number')
/**
* Generate a Random Number
*
* @param {Number} min The Minimum Number
* @param {Number} max The Maximum Number
*/
randomNum(min, max) {
if (typeof min !== 'number') throw new TypeError('minimum must be a number')
if (typeof max !== 'number') throw new TypeError('maximum must be a number')
const number = Math.floor(Math.random() * (max - min + 1)) + min
return number
},
const number = Math.floor(Math.random() * (max - min + 1)) + min
return number
},
/**
* Generate a Random Boolean
*/
randomBol() {
const boolean = Math.floor(Math.random() * (2 - 1 + 1)) + 1
return (boolean === 1)
},
/**
* Generate a Random Boolean
*/
randomBol() {
const boolean = Math.floor(Math.random() * (2 - 1 + 1)) + 1
return (boolean === 1)
},
/**
* Generate a Random String
*
* @typedef {Object} randomStr { pages: Object, events: Object, urls: RouteList, bind: String, cors: Boolean, port: Number, body: Number }
* @prop {Number} length The Length of the String
* @prop {Boolean} numbers Whether Numbers should be included
* @prop {Boolean} symbols Whether Symbols should be included
* @prop {Boolean} uppercase Whether Uppercase letters should be included
* @prop {Boolean} lowercase Whether Lowercase letters should be included
* @prop {String} exclude Characters that should not be included
*
* @param {randomStr} options
*/
randomStr(options) {
if (typeof options !== 'object') throw new TypeError('options must be an object')
/**
* Generate a Random String
*
* @typedef {Object} randomStr { length: number, numbers: boolean, symbols: boolean, uppercase: boolean, lowercase: boolean, exclude: string }
* @prop {Number} length The Length of the String
* @prop {Boolean} numbers Whether Numbers should be included
* @prop {Boolean} symbols Whether Symbols should be included
* @prop {Boolean} uppercase Whether Uppercase letters should be included
* @prop {Boolean} lowercase Whether Lowercase letters should be included
* @prop {String} exclude Characters that should not be included
*
* @param {randomStr} options
*/
randomStr(options) {
if (typeof options !== 'object') throw new TypeError('options must be an object')
const string = require('./utils/randomString').generate(options)
return string
},
const string = require('./utils/randomString').generate(options)
return string
},
/**
* Generate a Spinner
*/
spinner: class spinner {
constructor() {
this.state = 0
this.states = [
'/', '-',
'\\', '|'
]
}
/**
* Generate a Spinner
*/
spinner: class spinner {
constructor() {
this.state = 0
this.states = [
'/', '-',
'\\', '|'
]
}
get() {
if (this.state >= 4) this.state = 0
this.state++
get() {
if (this.state >= 4) this.state = 0
this.state++
return this.states[this.state-1]
}
}
return this.states[this.state-1]
}
},
/**
* Encrypt a String
*
* @typedef {Object} encryptStr { algorithm: string, key: string, key: string }
* @prop {String} [algorithm] The Algorithm to use
* @prop {String} [output] The Text Output (hex, utf8, ...)
* @prop {String} text The Text to Encrypt
* @prop {String} [key] The Key
*
* @param {encryptStr} options
*/
encryptString(options) {
if (typeof options !== 'object') throw new TypeError('options must be an object')
const data = require('./utils/cryptString').encrypt(options)
return data
},
/**
* Decrypt a String
*
* @typedef {Object} decryptStr { algorithm: string, key: string, key: string }
* @prop {String} [algorithm] The Algorithm to use
* @prop {String} [output] The Text Input (hex, utf8, ...)
* @prop {String} text The Text to Encrypt
* @prop {String} [key] The Key
*
* @param {decryptStr} options
*/
decryptString(options) {
if (typeof options !== 'object') throw new TypeError('options must be an object')
const data = require('./utils/cryptString').decrypt(options)
return data
}
}

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

const crypto = require('node:crypto')
const crypto = require('crypto')

@@ -3,0 +3,0 @@ const RANDOM_BATCH_SIZE = 256

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