+ 2

I'm creating a library

Hi, I wanted to ask for some suggestions about a library I' m developing called EasyJavaScript. It' s made to make JS easier and simplier to use. I made 6 functions for now, who are: ------------------------------ copy(string to copy) => To copy to clipboard the string you ' ve specified in the 1st parameter random(max number) => To have a random number from 0 to the number you' ve specified in the 1st parameter clock() => To have the exact time with this pattern: hh:mm:ss docId(id) => It substitutes document.getElementById(id) docTag(tag, numb) => It substitutes document.getElementsByTagName(tag)[numb] docClass(class, numb) => It substitutes document.getElementsByClass(class)[numb] ------------------------------ I don' t know what to add any suggestion?

4th Mar 2021, 10:19 PM
Gabriele Giambrone
Gabriele Giambrone - avatar
2 Réponses
0
There a ton of libraries out there which make JS simpler. But if you feel like making your own, you should go for it. Here are some options you might want to consider: - addClass method for Element - remClass method for Element - hasClass method for Element - toggleClass method for Element - on (instead of addEventListener) method for Element - capitilize method for String - contains method for String and Array - random method for Array (returns a random array value) - hasDuplicates method for Array - getKeyByValue method for Object These are just suggestions, but I hope you find at least some it useful. Good luck! EDIT: // Library examples docId = document.getElementById.bind(document); // NOTE: you may try to use an arrow function here, but i find it doesn't work well with the prototype method Array.prototype.contains = function (value) { return this.indexOf(value) > -1; }; // Use case examples docId("demo"); // Returns Element let arr = ["a", "b", "c"]; arr.contains("b"); // Returns true
5th Mar 2021, 9:55 AM
Ronald J. Tempel
Ronald J. Tempel - avatar
+ 2
Thanks Ronald J. Tempel 😊 ( I know, I saw it only now :| )
10th Mar 2021, 10:40 PM
Gabriele Giambrone
Gabriele Giambrone - avatar