New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bettercorp/tools

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bettercorp/tools - npm Package Compare versions

Comparing version 1.3.20220428202640 to 2.0.20220606181055

8

lib/index.d.ts

@@ -1,1 +0,7 @@

export {};
import { Tools } from "./Tools";
import * as Vue from "./Vue";
declare const _default: {
Tools: typeof Tools;
Vue: typeof Vue;
};
export default _default;

@@ -7,2 +7,6 @@ "use strict";

module.exports.Vue = Vue.default;
exports.default = {
Tools: Tools_1.Tools,
Vue,
};
//# sourceMappingURL=index.js.map

@@ -1,4 +0,17 @@

import * as MOMENT from 'moment';
import { MergeObjectsKey, SimpleStatu } from './Interfaces';
import * as MOMENT from "moment";
import { IDictionary, MergeObjectsKey, SimpleStatu } from "./Interfaces";
export declare enum CleanStringStrength {
soft = "soft",
hard = "hard",
url = "url",
ip = "ip"
}
export declare class Tools {
static readonly regexes: {
hard: RegExp;
soft: RegExp;
url: RegExp;
ip: RegExp;
};
static cleanString(objectToClean: any, maxLimit?: number, strength?: CleanStringStrength, returnNullAndUndefined?: boolean): string | null | undefined;
static enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[];

@@ -15,3 +28,2 @@ static encrypt(text: string, key: string): string;

static decodeBase64Image(dataString: string): any;
static MemoryStream(options?: any): any;
private static GetValueFromObjectBasedOnStringPathSearcher;

@@ -43,2 +55,10 @@ static GetValueFromObjectBasedOnStringPath(workingObj: any, stringToGet: string): any;

static GetInANiceFormat(speed: number, type?: string, roundTo?: number): string;
static clampNumber(min: number, max: number, value: number): number;
static sleep(milliseconds?: number): Promise<void>;
static arrays: {
groupListBy: <T = any>(groupFunc: (object: T) => string, list: T[]) => IDictionary<T[]>;
collectListBy: <T_1 = any>(groupFunc: (object: T_1) => string, list: T_1[]) => T_1[][];
head: <T_2 = any>(list: T_2[]) => T_2 | undefined;
tail: <T_3 = any>(list: T_3[]) => T_3 | undefined;
};
}

251

lib/Tools.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tools = void 0;
exports.Tools = exports.CleanStringStrength = void 0;
const MOMENT = require("moment");
const CryptoAES = require("crypto-js/aes");
const CryptoENC = require("crypto-js/enc-utf8");
const clone = require('just-clone');
var stream = require('stream');
var Transform = stream.Transform;
function MemoryStream(options) {
return new Transform({
transform(chunk, encoding, callback) {
this.push(chunk);
callback();
},
});
}
const clone = require("just-clone");
var CleanStringStrength;
(function (CleanStringStrength) {
CleanStringStrength["soft"] = "soft";
CleanStringStrength["hard"] = "hard";
CleanStringStrength["url"] = "url";
CleanStringStrength["ip"] = "ip";
})(CleanStringStrength = exports.CleanStringStrength || (exports.CleanStringStrength = {}));
class Tools {
static cleanString(objectToClean, maxLimit = 255, strength = CleanStringStrength.hard, returnNullAndUndefined = false) {
let regx = Tools.regexes.hard;
switch (strength) {
case CleanStringStrength.soft:
regx = Tools.regexes.soft;
break;
case CleanStringStrength.url:
regx = Tools.regexes.url;
break;
case CleanStringStrength.ip:
regx = Tools.regexes.ip;
break;
}
let data = `${objectToClean}`
.trim()
.replace(regx, "")
.trim()
.substring(0, maxLimit || 255);
if (data === "undefined")
return returnNullAndUndefined ? undefined : "";
if (data === "null")
return returnNullAndUndefined ? null : "";
return data;
}
static enumKeys(obj) {
return Object.keys(obj).filter(k => Number.isNaN(+k));
return Object.keys(obj).filter((k) => Number.isNaN(+k));
}

@@ -56,3 +77,4 @@ static encrypt(text, key) {

if (pathSplit.length < 2) {
workingTemplate[iPath] = this._setUpdatedTemplatePathFinderArrayHandler(isStrNu.value, workingTemplate[iPath], endObj);
workingTemplate[iPath] =
this._setUpdatedTemplatePathFinderArrayHandler(isStrNu.value, workingTemplate[iPath], endObj);
return workingTemplate;

@@ -93,6 +115,6 @@ }

for (let i in obj) {
if ((typeof obj[i]) == 'object') {
if (typeof obj[i] == "object") {
let tempB = this._flattenObject(obj[i]);
for (let j in tempB) {
tempA[i + '.' + j] = tempB[j];
tempA[i + "." + j] = tempB[j];
}

@@ -108,3 +130,3 @@ }

if (!this.isObject(obj))
throw 'Not a valid object!';
throw "Not a valid object!";
return this._flattenObject(obj);

@@ -128,11 +150,8 @@ }

if (this.isNullOrUndefined(matches) || matches.length !== 3) {
return new Error('Invalid input string');
return new Error("Invalid input string");
}
response.type = matches[1];
response.data = new Buffer(matches[2], 'base64');
response.data = Buffer.from(matches[2], "base64");
return response;
}
static MemoryStream(options) {
return MemoryStream(options);
}
static GetValueFromObjectBasedOnStringPathSearcher(workingObj, stringToGet) {

@@ -145,5 +164,14 @@ if (this.isNullOrUndefined(workingObj)) {

}
// new version? requires more tests
/*return stringToGet
.replace(/\[([^[\]]*)]/g, ".$1.")
.split(".")
.filter((prop) => prop !== "")
.reduce(
(prev, next) => (prev instanceof Object ? prev[next] : undefined),
workingObj
);*/
let splitted = stringToGet.split(".", 2);
if (splitted.length === 1) {
if (splitted[0] === '*') {
if (splitted[0] === "*") {
let data = [];

@@ -173,3 +201,5 @@ for (let iI of Object.keys(workingObj)) {

let retData = this.GetValueFromObjectBasedOnStringPathSearcher(workingObj, stringToGet);
return this.isNullOrUndefined(retData) ? retData : JSON.parse(JSON.stringify(retData));
return this.isNullOrUndefined(retData)
? retData
: JSON.parse(JSON.stringify(retData));
}

@@ -181,3 +211,5 @@ for (let val of splitObj) {

let retData = this.GetValueFromObjectBasedOnStringPathSearcher(workingObj, val);
let data = this.isNullOrUndefined(retData) ? retData : JSON.parse(JSON.stringify(retData));
let data = this.isNullOrUndefined(retData)
? retData
: JSON.parse(JSON.stringify(retData));
if (this.isUndefined(data)) {

@@ -220,7 +252,12 @@ finalString += val;

let strToReplace = str;
if (strToReplace.indexOf('{') >= 0) {
let strSplt = strToReplace.split('{');
let strSplt2 = strSplt[1].split('}');
if (strToReplace.indexOf("{") >= 0) {
let strSplt = strToReplace.split("{");
let strSplt2 = strSplt[1].split("}");
let newVal = this.GetValueFromObjectBasedOnStringPath(obj, strSplt2[0]);
strToReplace = strSplt[0] + newVal + strSplt2.splice(1).join('}') + (strSplt.length > 2 ? '{' : '') + strSplt.splice(2).join('{');
strToReplace =
strSplt[0] +
newVal +
strSplt2.splice(1).join("}") +
(strSplt.length > 2 ? "{" : "") +
strSplt.splice(2).join("{");
strToReplace = this.StringReplaceWithObject(obj, strToReplace);

@@ -261,6 +298,6 @@ }

if (count > timeout && rejectFunc) {
rejectFunc('Timeout!');
rejectFunc("Timeout!");
}
if (count > timeout) {
throw 'Timeout!';
throw "Timeout!";
}

@@ -271,3 +308,3 @@ await this.delay(time);

static isString(value) {
return typeof value === 'string' || value instanceof String;
return typeof value === "string" || value instanceof String;
}

@@ -282,12 +319,15 @@ static isDate(value, matchString = true) {

static isArray(value) {
return !this.isNullOrUndefined(value) && typeof value === 'object' && value.constructor === Array && !this.isNullOrUndefined(value.length);
return (!this.isNullOrUndefined(value) &&
typeof value === "object" &&
value.constructor === Array &&
!this.isNullOrUndefined(value.length));
}
static isFunction(value) {
return typeof value === 'function';
return typeof value === "function";
}
static isSymbol(value) {
return typeof value === 'symbol';
return typeof value === "symbol";
}
static isNumber(value) {
return typeof value === 'number' && !isNaN(value);
return typeof value === "number" && !isNaN(value);
}

@@ -299,7 +339,7 @@ static isStringNumber(value) {

const valueAsString = `${value}`;
if (valueAsString.split('.').length > 2)
if (valueAsString.split(".").length > 2)
return { status: false };
if (valueAsString.split(',').length > 2)
if (valueAsString.split(",").length > 2)
return { status: false };
if (!(/^[0-9 ,.\-]{1,}$/g.test(valueAsString)))
if (!/^[0-9 ,.\-]{1,}$/g.test(valueAsString))
return { status: false };

@@ -314,6 +354,6 @@ let nValue = Number.parseFloat(valueAsString);

static isBoolean(value) {
return typeof value === 'boolean';
return typeof value === "boolean";
}
static isUndefined(value) {
return typeof value === 'undefined';
return typeof value === "undefined";
}

@@ -326,3 +366,3 @@ static isNull(value) {

return false;
return value && typeof value === 'object' && value.constructor === Object;
return value && typeof value === "object" && value.constructor === Object;
}

@@ -339,8 +379,8 @@ static isNullOrUndefined(value) {

switch (symbol.toUpperCase()) {
case 'USD':
return '$';
case 'ZAR':
return 'R';
case 'GBP':
return '£';
case "USD":
return "$";
case "ZAR":
return "R";
case "GBP":
return "£";
}

@@ -350,9 +390,15 @@ return symbol;

static formatCurrency(amount, decimalPlaces, decimalFormatter, thousandsFormatter, symbol) {
decimalPlaces = this.isNullOrUndefined(decimalPlaces) ? 2 : Math.abs(decimalPlaces);
decimalFormatter = this.isNullOrUndefined(decimalFormatter) ? '.' : decimalFormatter;
thousandsFormatter = this.isNullOrUndefined(thousandsFormatter) ? ' ' : thousandsFormatter;
decimalPlaces = this.isNullOrUndefined(decimalPlaces)
? 2
: Math.abs(decimalPlaces);
decimalFormatter = this.isNullOrUndefined(decimalFormatter)
? "."
: decimalFormatter;
thousandsFormatter = this.isNullOrUndefined(thousandsFormatter)
? " "
: thousandsFormatter;
if (!this.isNumber(amount)) {
amount = Number.parseFloat(amount);
}
const negative = (amount < 0 ? '-' : '');
const negative = amount < 0 ? "-" : "";
amount = Math.abs(amount || 0);

@@ -362,17 +408,18 @@ amount = amount.toFixed(decimalPlaces);

if (this.isBoolean(symbol) && symbol === false) {
symbol = '';
symbol = "";
}
else {
symbol = 'R';
symbol = "R";
}
}
const numberValueSplit = amount.split('.');
let decimalValue = '';
const numberValueSplit = amount.split(".");
let decimalValue = "";
if (decimalPlaces > 0) {
decimalValue = decimalFormatter + numberValueSplit[1];
}
return symbol
+ ' ' + negative
+ numberValueSplit[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandsFormatter)
+ decimalValue;
return (symbol +
" " +
negative +
numberValueSplit[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandsFormatter) +
decimalValue);
}

@@ -384,54 +431,54 @@ static genRandomNumber(min, max) {

switch (type) {
case 'GB': {
case "GB": {
if (amt >= 1000) {
return 'TB';
return "TB";
}
return 'GB';
return "GB";
}
case 'MB': {
case "MB": {
if (amt >= 1000) {
return this.GetKeyForFormat('GB', amt / 1000);
return this.GetKeyForFormat("GB", amt / 1000);
}
return 'MB';
return "MB";
}
case 'KB': {
case "KB": {
if (amt >= 1000) {
return this.GetKeyForFormat('MB', amt / 1000);
return this.GetKeyForFormat("MB", amt / 1000);
}
return 'MB';
return "MB";
}
case 'B': {
case "B": {
if (amt >= 1000) {
return this.GetKeyForFormat('KB', amt / 1000);
return this.GetKeyForFormat("KB", amt / 1000);
}
return 'MB';
return "MB";
}
case 'Gb': {
case "Gb": {
if (amt >= 1000) {
return 'Tbps';
return "Tbps";
}
return 'Gbps';
return "Gbps";
}
case 'Mb': {
case "Mb": {
if (amt >= 1000) {
return this.GetKeyForFormat('Gb', amt / 1000);
return this.GetKeyForFormat("Gb", amt / 1000);
}
return 'Mbps';
return "Mbps";
}
case 'Kb': {
case "Kb": {
if (amt >= 1000) {
return this.GetKeyForFormat('Mb', amt / 1000);
return this.GetKeyForFormat("Mb", amt / 1000);
}
return 'Kbps';
return "Kbps";
}
case 'b': {
case "b": {
if (amt >= 1000) {
return this.GetKeyForFormat('Kb', amt / 1000);
return this.GetKeyForFormat("Kb", amt / 1000);
}
return 'bps';
return "bps";
}
}
return 'x';
return "x";
}
static GetFormatted(speed, type = 'MB', roundTo = 2) {
static GetFormatted(speed, type = "MB", roundTo = 2) {
while (speed >= 1000) {

@@ -442,3 +489,3 @@ speed = speed / 1000;

}
static GetInANiceFormat(speed, type = 'MB', roundTo = 2) {
static GetInANiceFormat(speed, type = "MB", roundTo = 2) {
const key = this.GetKeyForFormat(type, speed);

@@ -450,4 +497,34 @@ while (speed >= 1000) {

}
static clampNumber(min, max, value) {
if (min > max)
throw new Error("min cannot be greater than max");
return value < min ? min : value > max ? max : value;
}
static async sleep(milliseconds = 1000) {
await new Promise((r) => setTimeout(r, milliseconds));
}
}
exports.Tools = Tools;
Tools.regexes = {
hard: /(?![,-:~_])[\W]/g,
soft: /(?![,-:~ +_.@])[\W]/g,
url: /(?![,-:~ +_.@\/\?=&%])[\W]/g,
ip: /(?![.0-9])[\W]/g,
};
Tools.arrays = {
groupListBy: (groupFunc, list) => {
return list.reduce((prev, next) => (Object.assign(Object.assign({}, prev), { [groupFunc(next)]: [...(prev[groupFunc(next)] || []), next] })), {});
},
collectListBy: (groupFunc, list) => {
return Object.values(Tools.arrays.groupListBy(groupFunc, list));
},
/* Get the first item in the array */
head: (list) => {
return list[0];
},
/* Get the last item in the array */
tail: (list) => {
return list[list.length - 1];
},
};
//# sourceMappingURL=Tools.js.map

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

{"name":"@bettercorp/tools","scripts":{"dev":"nodemon -L --watch src/**/*.ts --watch plugins/**/*.ts --exec ts-node src/index.ts","start":"node lib/index.js","build":"tsc","deploy":"npm publish","version":"node ./build/version.js $0","test":"./node_modules/mocha/bin/mocha --reporter mocha-junit-reporter --reporter-options mochaFile=junit.xml","testDev":"./node_modules/mocha/bin/mocha"},"license":"AGPL-3.0-only","repository":{"url":"https://gitlab.com/BetterCorp/tools"},"files":["lib/**/*"],"main":"lib/index.js","version":"1.3.20220428202640","dependencies":{"@types/node":"^16.11.26","@types/uuid":"^8.3.1","crypto-js":"^4.1.1","events":"^3.3.0","express":"^4.17.3","just-clone":"^4.1.1","moment":"^2.29.1","stream":"0.0.2","uuid":"^8.3.2","ws":"^8.5.0"},"devDependencies":{"@types/crypto-js":"^4.1.1","mocha":"^9.2.1","mocha-junit-reporter":"^2.0.2","ts-node":"^10.7.0","tslint":"^6.1.3","typescript":"^4.6.2"}}
{"name":"@bettercorp/tools","scripts":{"dev":"nodemon -L --watch src/**/*.ts --watch plugins/**/*.ts --exec ts-node src/index.ts","start":"node lib/index.js","build":"tsc","deploy":"npm publish","version":"node ./build/version.js $0","test":"node ./node_modules/mocha/bin/mocha.js --reporter mocha-junit-reporter --reporter-options mochaFile=junit.xml","testDev":"node ./node_modules/mocha/bin/mocha.js"},"license":"AGPL-3.0-only","repository":{"url":"https://gitlab.com/BetterCorp/tools"},"files":["lib/**/*"],"main":"lib/index.js","version":"2.0.20220606181055","devDependencies":{"@types/crypto-js":"^4.1.1","mocha":"^10.0.0","mocha-junit-reporter":"^2.0.2","ts-node":"^10.8.1","tslint":"^6.1.3","typescript":"^4.7.3"},"dependencies":{"@types/node":"^17.0.40","crypto-js":"^4.1.1","just-clone":"^6.0.1","moment":"^2.29.3"}}

Sorry, the diff of this file is not supported yet

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