It Helps You To play with string and transform strings what are use in lots of cases of node.js application
LIKE:-
import { log, MakePriceString, mekeLinkString,GenerateOTP,repleCaracter } from "string-player"
by default it return 6 charecters unique otp each time
import {GenerateOTP,log} from 'string-player'
let otp=new GenerateOTP();
log(otp.getPin())//returns 271633
log(otp.getPin())//returns 474316
log(otp.getPin())//returns 706210
You can get opt of more or lest Carecter :-
import {GenerateOTP,log} from 'string-player'
let less=new GenerateOTP(4);// 4 Charecters
let more=new GenerateOTP(9);// 9 Charecters
let opt_of_4_charecters=less.getPin() //return unique value like 7927
let opt_of_9_charecters=more.getPin();//return unique value like 640821514;
console.log({opt_of_4_charecters,opt_of_9_charecters});
//prints
// { opt_of_4_charecters: 7927,opt_of_9_charecters: 640821514 }
import { log, repleCaracter } from "string-player"
log(repleCaracter(`
export function checkTimeString(time) {
if (typeof time != 'string') throw 'not a correct time ' + time
if (!time.includes(':')) throw 'not a correct time ' + time
if (time.length !== 5) throw 'not a correct time ' + time
time = time.split(':')
if (time.length !== 2) throw 'not a correct time array'
if (Number(time[0]).toString().toLowerCase == 'nan') throw 'not a correct time[0] ' + time[0]
if (Number(time[1]).toString().toLowerCase == 'nan') throw 'not a correct time[1] ' + time[1]
if (time[0] < 0 || time[0] > 23) throw 'not a correct time[1] ' + time[0]
if (time[1] < 0 || time[1] > 59) throw 'not a correct time[1] ' + time[1]
// log( time[0] > 11 ? Number(time[0]) - 11 : time[0])
let string = (time[0] > 12 ? Number(time[0]) - 12 : time[0]) + ':' + time[1] + ' ' + (time[0] > 11 ? 'PM' : 'AM');
return string
}`
))
prints
export function checkTimeString(time) {
if (typeof time != 'string') throw 'not a correct time ' + time
if (!time.includes(':')) throw 'not a correct time ' + time
if (time.length !== 5) throw 'not a correct time ' + time
time = time.split(':')
if (time.length !== 2) throw 'not a correct time array'
if (Number(time[0]).toString().toLowerCase == 'nan') throw 'not a correct time[0] ' + time[0]
if (Number(time[1]).toString().toLowerCase == 'nan') throw 'not a correct time[1] ' + time[1]
if (time[0] < 0 || time[0] > 23) throw 'not a correct time[1] ' + time[0]
if (time[1] < 0 || time[1] > 59) throw 'not a correct time[1] ' + time[1]
// log( time[0] > 11 ? Number(time[0]) - 11 : time[0])
let string = (time[0] > 12 ? Number(time[0]) - 12 : time[0]) + ':' + time[1] + ' ' + (time[0] > 11 ? 'PM' : 'AM');
return string
}
repleCrAll is use for repling string array
import { log, repleCaracter ,repleCrAll} from "string-player"
//repling 3 strings
let [functions , arrowFunctions,print]=repleCrAll(['function(){}', `()=>{}`, `console.log('hello')]`]);
//printing repled strings
console.log({ functions, arrowFunctions, print });
// printed Data
// {
// functions: 'function(){}',
// arrowFunctions: '()=>{}',
// print: 'console.log('hello')]'
// }
import { log, MakePriceString} from "string-player"
let a = 500;
a=await MakePriceString(a);
log(a)
//returns 500.00
import { log, mekeLinkString } from "string-player"
let a = 'https://www.your-website.com/a b c d f g e l k p n m o k j l i p q r s';
log(mekeLinkString(a))
//prints https://www.your-website.com/a-b-c-d-f-g-e-l-k-p-n-m-o-k-j-l-i-p-q-r-s
let reqData={
command :'INIT',
total_bytes:10240
}
log(makeUrlWithParams('https://upload.twitter.com/1.1/media/upload.json',reqData))
//returns 'https://upload.twitter.com/1.1/media/upload.json?command=INIT&total_bytes=10240
import { breakJsonData, log } from "./index.js"
let data=JSON.stringify({
A:'A',
B:'B',
C:'C',
D:'D',
bol:true,
fool:false,
arr:["alert","WebTransport","wet"],
e:"we"
})
log(data);
//prints
//{"A":"A","B":"B","C":"C","D":"D","bol":true,"fool":false,"arr":["alert","WebTransport","wet"],"e":"we"}
data= breakJsonData(data)
log(data);
//prints
// {
// "A":"A",
// "B":"B",
// "C":"C",
// "D":"D",
// "bol":true,
// "fool":false,
// "arr":[
// "alert",
// "WebTransport",
// "wet"
// ],
// "e":"we"
// }
import { breakJsonData, log } from "./index.js"
let data = {
0: 0,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
10: 10
}
log(data);
/*
it prints
{
'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
'10': 10
}
*/
You can contribute also by joining github-github Repository
import Validator from "./_lib/Validator.js";
let validate=new Validator({giveError:false});
console.log(validate.isAllEmty(['e','',null,undefined]));
//prints false
console.log(validate.isAllEmty(['',null,undefined]));
//prints true
import Validator from "./_lib/Validator.js";
let isEmail = val => (new Validator()).isEmail(val);
console.log(isEmail('mubtasim@gmail.com'));
//prints true;
console.log(isEmail('$mubtasim@gmail.com'));
//prints false;
console.log(isEmail('mubtasim@gmail..com'));
//prints false;
console.log(isEmail('mubtasim@@gmail.com'));
//prints false;
console.log(isEmail('mubtasim@gmail.c'));
//prints false;
console.log(isEmail('mubtasim@gmail.cm'));
//prints true;
console.log(isEmail('mubtasim@gmai,l.com'));
//prints false;
console.log(isEmail('[mubtasim@gmail.com]'));
//prints false;
console.log(isEmail('1mubtasim@gmail.com'));
//prints false;
You Check String is url or not By isValidUrl Function , Just Parse The string to the isValidUrl
console.log(isValidUrl('https://x.com/search?q=Building&src=trend_click&vertical=trends'));
***Follow Me ***
- Github Profile
- X twitter
- Upwork
- +8801750147694
- Location : Anowara , Chittagong , Bangladesh