Utiljin is a utility function created by Jinyong-Lee
you can install local or globally
npm install utiljin
npm install -g utiljin
const Utiljin = require("utiljin");
/** Array elements are created as many as the number entered as parameters (from 0 to 1, 2, 3...)
* @param {number} length
* @return {Array<number>}
*/
Utiljin.makeDummyNumberArray(10);
=> [0,1,2,3,4,5,6,7,8,9]
Utiljin.makeDummyNumberArray(15);
=> [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
/** Array elements are created as many as the number entered as the first parameter.
* Set the starting number in the second parameter
* length가 5 fromNumber 7이면 (7, 8, 9, 10, 11)
* length가 3 fromNumber 12이면 (12, 13, 14)
* @param {number} length
* @param {number} fromNumber
* @return {Array<number>}
*/
Utiljin.makeDummyNumberArray_fromNumber(5, 7)
=> [7, 8, 9, 10, 11]
Utiljin.makeDummyNumberArray_fromNumber(3, 12)
=> [12, 13, 14]
/**
Get a random number within the range of numbers entered as a parameter.
* @param {number} num
* @return {number}
*/
Utiljin.getRandomNumber(100)
=> 57 (random number from 0 to 100)
/**
Insert a , (comma) for every 3 digits
* @param {number} num
* @return {string}
*/
Utiljin.getCommaNumber(1000000000)
=> "1,000,000,000"
/** change the number of decimal places
* @param {number} num 변경할 숫자
* @param {number} fixed 소숫점 자릿수
* @return {string}
*/
Utiljin.getFixedNumber(10,2);
=> "10.00"
/** Returns true if foundStr is in str, false otherwise
*
* @param {string} str
* @param {string} findedStr
* @return {boolean}
*/
Utiljin.isFindString("karaoke","oke");
=> true
Utiljin.isFindString("jinyong","jacky");
=> false
/** Change the number to Korean Won
*
* @param {string | number} param_price
* @return {string}
*/
Utiljin.renderPrice("107,000,000");
=> 1억 700만
Utiljin.renderPrice(470000000);
=> 4억 7천만
/** Function to use to populate temporary data
* @param {number} lengthNumber
* @param {number} rangeNumber
* @param {number} decimalPoint
* @return {Array<number>}
*/
Utiljin.createDummyData(10,5,3);
=> [0.695, 0.42, 2.12, 4.751, 2.95, 1.499, 3.555, 1.263, 2.137, 1.188]
Utiljin.createDummyData(10,5,0);
=> [4, 4, 1, 3, 2, 5, 5, 3, 2, 3]
/** Function to use to populate temporary data (without random values)
* @param {Array<number>} arr
* @param {number} num
* @return {string}
*/
Utiljin.createDummyData_noRandom(10,5);
=> [5, 4, 3, 2, 1, 0, -1, -2, -3, -4]
Utiljin.createDummyData_noRandom(10,10);
=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
/** bubbleSort
* @param {Array<number>} array
* @return {Array<number>}
*/
Utiljin.bubbleSort([13,15,6,8,10]);
=> [6, 8, 10, 13, 15]
Utiljin.bubbleSort([5,2,4,1,3]);
=> [1, 2, 3, 4, 5]
/** selectionSort
* @param {Array<number>} array
* @return {Array<number>}
*/
Utiljin.selectionSort([13,15,6,8,10]);
=> [6, 8, 10, 13, 15]
Utiljin.selectionSort([5,2,4,1,3]);
=> [1, 2, 3, 4, 5]
/** true if the average of the two selected numbers in the array matches the second argument (expression 2 below) false if not matched (expression 1 below)
* @param {Array<number>} arr
* @param {number} num
* @return {boolean}
*/
Utiljin.averagePair([1,2,3,4,5],1);
=> false
Utiljin.averagePair([1,2,3,4,5],2);
=> true
/** Get Now Time
* @return {string}
*/
Utiljin.getDatetime();
=> '22-04-05 15 : 05 : 25' (now time)
/** Function to get the date of the previous month from the base date
* @param {number} param_month
* @param {string} baseDate?
* @returns {string}
*/
Utiljin.getDateTimePrevMonth_fromBaseTime(4);
=> '2021-12' (now time : 2022-04)
Utiljin.getDateTimePrevMonth_fromBaseTime(10, "2022-01");
=> '2021-03'
/** Function to get the date of the previous month from the base date
* @param {number} param_month
* @param {string} baseDate?
* @returns {string}
*/
Utiljin.getDateTimePrevMonth_fromBaseTime(4);
=> '2021-12' (now time : 2022-04)
Utiljin.getDateTimePrevMonth_fromBaseTime(10, "2022-01");
=> '2021-03'
/** convert number to hexadecimal
*
* @param {number} num
* @returns {string}
*/
Utiljin.toHex(100);
=> '64'
Utiljin.toHex(1000);
=> '3e8'
/** If the character that is the second argument exists in the first argument string, it is removed.
* @param {string} param_string
* @param {string} param_char
* @returns {string}
*/
Utiljin.deleteCharFromString("leejinyong","e")
=> 'ljinyong'
/** factorial.
* @param {number} num
* @returns {number}
*/
Utiljin.factorial(5);
=> 120
Utiljin.factorial(10);
=> 3628800
/** fibonaci.
* @param {number} num
* @returns {number}
*/
Utiljin.factorial(10);
=> 55
Utiljin.factorial(100);
=> 354224848179262000000
/** get Greatest Common Divisor
* @param {number} minNum
* @param {number} maxNum
* @returns {number}
*/
Utiljin.gcd(8,12);
=> 4
Utiljin.gcd(20,10);
=> 10
/** get Least Common Multiple.
* @param {Array<number>} arr
* @returns {number}
*/
Utiljin.lcm([330, 75, 450, 225]);
=> 4950
Utiljin.lcm([1,2,3,4,5,6,7,8,9]);
=> 2520
Utiljin.lcm([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]);
=> 360360
/** change the name of the extension
*
* @param {string} file name
* @param {string} extension Name
* @return {string}
*/
Utiljin.changeExtName("file.excel","txt");
=> "file.txt"
If you find some problem, contact me dhzl3332@gmail.com