Package Exports
- sussy-util
- sussy-util/build/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sussy-util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

Sussy Util
Just a few Functions and Classes made by me
Version 1.9.0
Table of Contents
Classes
- AbstractClass
- BetterMath
- Collection
- DateUtil
- ImprovedArray
- IsSomething
- Point
- PrimeNumbers
- Queue
- Random
- Set
- Stack
- StopWatch
- StringUtil
AbstractClass
This class allows you to make an abstract class in JavaScript.
Usage:
const { AbstractClass } = require('sussy-util'); class SUS extends AbstractClass { constructor() { super(SUS); // now it will throw an error if you try to make an instance of this class without extending it first } }
BetterMath
const { BetterMath } = require('sussy-util'); BetterMath.distance(...Point); // returns the total distance between all given points BetterMath.round(number, digit); // returns round a number to a certain digit BetterMath.square(number); // returns the square of a number BetterMath.greatestCommonDivisor(a, b); BetterMath.gcd(a, b); // identical to BetterMath.greatestCommonDivisor BetterMath.lowestCommonDenominator(a,b); BetterMath.lcm(a, b); // identical to BetterMath.lowestCommonDenominator BetterMath.average([13, 12, 11]); // returns the average value of a number array BetterMath.avg(); // identical to BetterMath.average BetterMath.median([12, 12, 11]); // returns the median value of a number array BetterMath.factorial(number); // returns the factorial value of given number
Collection
// create a collection const { Collection } = require('sussy-util'); const collection = new Collection(); //usage example collection.add({ key: /* your key */ , value: /* your value */ }); collection.put({ key: /* your key */ , value: /* your value */ }); // add or replace const value = collection.get(key); collection.remove(key); collection.toArray(); // returns a array of MapEntry collection.has(key); collection.missing(key); collection.toString(); collection.toJSONString(); collection.count(); // returns the amount of entries collection.clearMap(); // removes all elements
DateUtil
// get DateUtil class const { DateUtil } = require('sussy-util'); //static functions DateUtil.getCurrentDate(); // returns the current date DateUtil.today(); // returns the current date at 00:00:00 DateUtil.tomorrow(); // returns the next day at 00:00:00 DateUtil.yesterday(); // returns the last day at 00:00:00 DateUtil.conpareDates(date1,date2); // returns and interger based on which date is bigger DateUtil.equals(date1, date2); // returns boolean based of if both dates are identical DateUtil.getMonthAbbr(month); // returns the abbreviated month name based on the number given DateUtil.getMonthFullName(month); // returns the full month name based on the number given DateUtil.getDayAbbr(day); // returns the abbreviated day name based on the number given DateUtil.getDayFullName(day); // returns the full day name based on the number given DateUtil.isLeapYear(year); // returns boolean based on if the given year is a leap year DateUtil.weekFirstDay(); // returns the first week day of the current week DateUtil.weekLastDay(); // returns the last week day of the current week DateUtil.leapYearsInRange(12, 2020); // returns all leap years in the given range DateUtil.getMonthFirstDay(); // returns the first day of the current month DateUtil.getMonthLastDay(); // returns the last day of the current month DateUtil.toDate(); // returns a date object from number or date or extened classes DateUtil.isAfter(date1, date2); // returns boolean based on if the second date is after the first one DateUtil.isBefore(date1, date2); // returns boolean based on if the second date is before the first one DateUtil.yearsToMonths(number); // returns the amount of months in total based on years
ImprovedArray
// create a ImprovedArray const { ImprovedArray } = require('sussy-util'); const array = new ImprovedArray(/* put initial items here */); //usage example // getting items from array const elm = array[index]; //has all Array functions array.insertAt(index, ...values); // inserts items at index array.remove(index); // remove elements from array at index const index = array.getRandomIndex(); // returns random index of array const element = array.getRandomElement(); // returns element at random index array.clear(); // removes all elements array.clone(); // returns clone const empty = array.isEmpty(); // returns if the array is empty true else false array.none(function); // returns true if none of the array elements fits the specified function array.rejected(function); // opposite of Array.prototype.filter array.sum(); // returns the sum of all elements of the array array.removeDuplicates(); // removes duplicates array.scramble(); // scrambles the array | deprecated array.countOccurrences(value); // counts how often the value given is in the array array.flatten(); // flattens the array array.toJSONString(); array.shuffle(); // shuffles the array array.findCommonElements(array); // returns new array with elements wich are in both arrays array.each((e,i,array) => {}); // shorter version of Array.forEach
IsSomething
// get IsSomething class const { IsSomething } = require('sussy-util'); // static methods IsSomething.isArray(); // returns true if the given value is a array IsSomething.isBoolean(); // returns true if the given value is a boolean IsSomething.isClass(); // returns if the given value is a class constructor IsSomething.isDate(); // returns true if the given value is a instanceof Date IsSomething.isError(); // returns true if the given value is a instanceof Error IsSomething.isEven(); // returns true if the given number is even returns null if given value is not a number IsSomething.isFunction(); // returns true if the given value is a function IsSomething.isNullorUndefined(); // returns true if the given value is null or undefined IsSomething.isNumber(); // returns true if the given value is a number or a string which contains only digits IsSomething.isObject(); // returns true if the given value is a object but not an array IsSomething.isPrime(); // returns true if the given number is a prime number returns null if given value is not a number IsSomething.isRegExp(); // returns true if the given value is a regular expression IsSomething.isString(); // returns true if the given value is a string IsSomething.isSymbol(); // returns true if the given is a instanceof Symbol IsSomething.isType(variable, type); // returns true if the given variable is of type type IsSomething.isInstanceOf(object, classConstructor); // returns true if given object is an instance on said class IsSomething.isDateValid(date); // checks if given date is valid
Point
const { Point } = require('sussy-util'); const point = new Point(x, y); point.distanceTo(new Point(x2, y2)); point.slopeTo(new Point(x3, y3));
PrimeNumbers
Get prime numbers and save them in an array for later use
const { PrimeNumbers } = require('sussy-util'); const primes = new PrimeNumbers(); primes.getTill(highedsNumber); primes.addPrimes(amount);
Queue
const { Queue } = require('sussy-util'); const queue = new Queue(); queue.push(...elements); queue.peek(); queue.shift();
Random
const { Random } = require('sussy-util'); Random.randomInt(upper, lower); // returns a random integer with upper and lower bounds given Random.randomDouble(upper, lower); // returns a random double with upper and lower bounds Random.randomString(length, charset?); // returns a random string with given length and charset Random.randomChar(charset?); // returns a random char with given charset Random.randomElement(array?); // returns a random element of an array Random.randomElementInRange(array?); // returns a random element of an array in range
Set
// create a Set const { Set } = require('sussy-util'); const set = new Set(); //usage example set.push(elm); // put elm in set if not already in set set.delete(elm); // removes the first elements which equals elm set.isEmpty(); // returns if set is empty const elm = set.get(index); // returns elm at index const length = set.length(); // returns number of elements in set set.remove(number); // removes the element at index set.changeCheckFunction(() => {}); // changes the check function for each element set.toString(); set.toJSONString();
Stack
// create a Stack const { Stack } = require('sussy-util'); const stack = new Stack(); //usage example stack.push(...elm); // put elm on top of stack const value = stack.pop(); // returns value on top of stack and removes it const value = stack.peek(); // returns value on top of stack without removing it stack.empty(); // returns if stack is empty stack.toArray(); // returns stack as array stack.toString(); stack.toJSONString();
StopWatch
const { StopWatch } = require('sussy-util'); const stopwatch = new StopWatch(); // stopwatch start at objet creation stopwatch.pause(); // pauses the stopwatch stopwatch.resume(); // resumes the stopwatch stopwatch.reset(); // resets the stopwatch stopwatch.time(); // returns the current time in milliseconds
StringUtil
// get StringUtil class const { StringUtil } = require('sussy-util'); //static function example usage StringUtil.reverse("Sussy"); // reverses the string | output: yssus StringUtil.isDiscordUsername("Sussy#1234"); // checks if string is a discord username | output: true StringUtil.isStrongPassword("kaljsd"); // checks if string is a strong password | output: false StringUtil.isWeakPassword("kaljsd"); // checks if string is a weak password | output: true StringUtil.isEmail("sussyBalls@gmail.com"); // checks if string is a email | output: true StringUtil.isInteger("12wqeq"); // output: false StringUtil.isURL("https://sus.com/"); // output: true StringUtil.shorten("Amogus SUS", length, elipse count); StringUtil.slugify("Amogus SUS"); // returns amogus-sus StringUtil.stripHtmlTags("<sussy> balls </sussy>") // removes html tags | returns balls StringUtil.capitalize("no bitches?"); // Makes the first letter uppercase and the rest lowercase | returns No bitches? StringUtil.isIPv6("::1"); // checks if string is a IPv6 address | returns true StringUtil.isIPv4("127.0.0.1"); // checks if string is a IPv4 address | returns true StringUtil.isIP("168.10.0.1"|"c927:501c:abf9:bc8f:c86d:541a:c354:120f"); // checks whether string is a IP address or not | eturns true StringUtil.isMacAddress("82-D3-32-D3-5D-43"); // checks if string is a MAC address | returns true StringUtil.isPhoneNumber(""); // checks if string is a phone number StringUtil.camelCase("sus amogus"); // uses the capitalize function | returns Sus Amogus StringUtil.randomColorCode(); // returns random hex color code StringUtil.randomCharacter(charset?); // returns a random character based on the current charset StringUtil.randomString(length, charset?); // returns a random string with the length given StringUtil.randomDiscordUsername(withSufix:boolean); // returns a random string with length 4 - 32 if withSufix is true then # and 4 random numbers will be added StringUtil.generatePassword(length, charset?); // returns a random strong password with given length if charset allows it StringUtil.wordCount(string); // returns the amount of words in the string StringUtil.getRatingString(number of stars); // 1 - 5 stars returns full/empty stars StringUtil.normalizeLineBreaks(string, lineEnd?); // returns string with only one type of line break StringUtil.contains(string, searchsParam); // returns boolean based on if the second string is in the first string StringUtil.repeat(string, number); // returns string repeated number amount of times StringUtil.rpad(string, number); // returns string padded on the right site to given length: number StringUtil.lpad(string, number); // returns string padded on the left site to given length: number StringUtil.uncapitalize(string); StringUtil.isFloat(string); StringUtil.splice(); StringUtil.rtrim(" sususu "); // return: " sususu" StringUtil.ltrim(" sususu "); // return: "sususu " StringUtil.camelToKebab(); StringUtil.isPalindrome("")
Functions
- addProperty
- asyncHandler
- asyncTimeout
- attributesToArray
- betterRound
- bytesToSize
- callbackify
- callIfFunction
- deepClone
- getObjectKeys
- getTypeString
- hasProperty
- hasValue
- measureTime
- merge
- objectToString
- removeFirstDigit
- removeLastDigit
- removeProperty
- removeXDigits
- strickJSONParse
- syncTimeout
addProperty
const { addProperty } = require('sussy-util'); addProperty({sus:true}, "imposter", true); // output: { sus:true, imposter:true }
asyncHandler
const { asyncHandler } = require('sussy-util'); const [ result, error ] = await asyncHandler(promiseFunction, params); if(error) { console.log(error); } if(result) { // do stuff }
asyncTimeout
const { asyncTimeout } = require('sussy-util'); await asyncTimeout(time_in_milliseconds);
attributesToArray
const { attributesToArray } = require('sussy-util'); attributesToArray({ sus:true, imposter:true }, true); // output: [true, true];
betterRound
Deprecated
const { betterRound } = require('sussy-util'); console.log(betterRound(123.56, 1)); // output: 123.6
bytesToSize
const { bytesToSize } = require('sussy-util'); const bytesString = bytesToSize(12300); console.log(bytesString); // output: 12.0 KB
callbackify
const { callbackify, betterRound } = require('sussy-util'); callbackify(betterRound, (res, err) => { if(err) { //do something } console.log(res); // output: 123.12 }, 123.123, 2);
callIfFunction
const { callIfFunction } = require('sussy-util'); callIfFunction(() => true); // output: true callIfFunction({hi:false}); // output: null
deepClone
const { deepClone } = require('sussy-util'); deepClone({er:true, us:{or:true}}): // output: {er:true, us:{or:true}}
getObjectKeys
const { getObjectKeys } = require('sussy-util'); getObjectKeys({ sus_:true, nein:false }); // output: ["sus_", "nein"]
getTypeString
const { getTypeString } = require('sussy-util'); getTypeString(213); // output: number getTypeString("sad"); // output: string getTypeString(class sus { constructor(){} }); // output: class getTypeString(() => {}); // output: function
hasProperty
const { hasProperty } = require('sussy-util'); hasProperty({ sus:true }, "sus"); // output: true
hasValue
const { hasValue } = require('sussy-util'); console.log(hasValue(123)); // output: true console.log(hasValue([]); // output: false console.log(hasValue([23]); // output: true console.log(hasValue([[],[]]); // output: false console.log(hasValue(() => {})); // output: true console.log(hasValue(undefined)); // output: false console.log(hasValue(true)); // output: true console.log(hasValue(false)); // output: true console.log(hasValue(new RegExp())); // output: false console.log(hasValue(new RegExp("sus")); // output: true console.log(hasValue(""); // output: false console.log(hasValue(" amogus "); // output: true
measureTime
const { measureTime } = require('sussy-util'); measureTime(label, function, params); // logs the time it takes to run the function
merge
const { merge } = require('sussy-util'); console.log(merge({ a:12, b:34 }, { m:34 })); // output: { a:12, b:34, m:34 }
objectToString
const { objectToString } = require('sussy-util'); objectToString({}); // output: [object Object]
removeFirstDigit
const { removeFirstDigit } = require('sussy-util'); console.log(removeFirstDigit(123); // output: 23
removeLastDigit
const { removeLastDigit } = require('sussy-util'); console.log(removeLastDigit(123)); // output: 12
removeProperty
const { removeProperty } = require('sussy-util'); removeProperty({ sus:true, imposter:true }, "imposter"); // output: { sus:true }
removeXDigits
const { removeXDigits } = require('sussy-util'); console.log(removeXDigits(7213, 3); // removes x amount of digits from behind | output: 7
strickJSONParse
const { strickJSONParse } = require('sussy-util'); strickJSONParse("{ sus:true }"); // output: { sus:true }
syncTimeout
const { syncTimeout } = require('sussy-util'); syncTimeout(time_to_wait);
Types and Interfaces
MapEntry
const { MapEntry } = require('sussy-util'); const keyValue = {} as MapEntry; console.log(keyValue); // output: { key: undefined, value: undefined };
MutableObject
const { MutableObject } = require('sussy-util'); const sussy = { sus:true, imposter:true, mine:"no" } as MutableObject<any>; sussy["temp"] = 3; // allowed
PromiseOr
const { PromiseOr } = require('sussy-util'); function dummy():PromiseOr<string> {}; // returns promise<string> | string
Updating
Going from 1.0.X to 1.1.X
renamed Class impArray to improvedArray
// old const { impArray } = require('sussy-util'); const array = new impArray(); // new const { improvedArray } = require('sussy-util'); const array = new improvedArray();
Going from 1.1.X to 1.2.X
renamed Class improvedArray to ImprovedArray
// old const { improvedArray } = require('sussy-util'); const array = new improvedArray(); // new const { ImprovedArray } = require('sussy-util'); const a = new ImprovedArray();
Going from 1.4.X to 1.5.X
Made all the non static String Functions static
// old const { StringUtil } = require('sussy-util'); const util = new StringUtil(); util.generatePassword(length); // new const { StringUtil } = require('sussy-util'); StringUtil.generatePassword(length, charset?);
Going from 1.5.X to 1.6.X
Brought all isSomething functions into the IsSomething class as static functions
// old const { isFunction } = require('sussy-util'); isFunction(() => { return true }) // output: true // new const { IsSomething } = require('sussy-util'); IsSomething.isFunction(() => {}); // output: true
Going from 1.6.X to 1.7.X
// old const { getNumberInRange } = require('sussy-util'); getNumberInRange(1,4); // new const { Random } = require('sussy-util'); Random.randomInt(1,4);
Going from 1.8.X to 1.9.X
// old const { betterRound } = require('sussy-util'); betterRount(12.34, 1); // new const { BetterMath } = require('sussy-util'); BetterMath.round(12.34, 1);