Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 11, 2021 04:14 pm GMT

PolyFull - enhance js capabilities

Javascript is a very nice language (at least for someone ) but it's still missing some core functionalities...

are you wondering which functionality are missing in the language? well, to remove an element from an array like now looks like this:

someArray.splice(someArray.indexOf(elementYouWantToRemove), 1)

and if you have to remove each occurrence of that element can be even worse:

for (let i = 0; i < someArray.length; i++) {    if (elementYouWantToRemove === someArray[i]) {        someArray.splice(i, 1)        i--    }}

not sure why javascript doesn't have such a basic functionality, something like this will be great:

someArray.remove(someElement)

well, i have a great news for you!

this and many many other functionalities are available directly into the language throught polyfull

all you need to do to unlock that functionalities is to import it in the index of your project:

import 'polyfull'

THIS IS INTENDED TO USE ONLY IN FINAL APPLICATIONS.

if you use this in library, any other applications that use your library will have polyfull injected as well.

please DO NOT use this if you are building a library, use this only where you have control of your node interpreter.

also, if you are using some other polyfiller, be sure that there is no overlaps, or something will broke. Thanks!

and you can use a lot of functionalities, here is an example:

import 'polyfull'// ArrayConstructorArray.zip([1, 2, 3], ['a', 'b', 'c']) // => [[1, 'a'], [2, 'b'], [3, 'c']]Array.collapse([1], [2, 3], [4, 5, 6]) // => [1, 2, 3, 4, 5, 6]Array.intersect([1, 2, 3], [2, 3, 4]) // => [2, 3]Array.unique([1, 2], [2, 3], [3, 4]) // [1, 2, 3, 4]// Array[1, 2, 3].remove(2) // => [1, 3][1, 2, 3].removeIndex(2) // => [1, 2][1, 2, 3].first() // => 1[1, 2, 3].last() // => 3// DateConstructorDate.current() // => new Date(Date.now())// Datenew Date(0).addHours(1) // => 1970-01-01T01:00:00.000Znew Date(0).isBefore(new Date(Date.now())) // => truenew Date(0).isAfter(new Date(Date.now())) // => falsenew Date(0).diff(new Date()) // => how many ms passed from 1970? :D// NumberConstructorNumber.random() // => -789.0123Number.random(0) // => 789.0123Number.random(0, 100) // => 89.0123Number.randomInt(0) // => 42// Number7.0.isPrime() // => true3.0.pow(2) // => 640.0.goldenRation() // => [24.72~, 15.28~]50.0.percentage(20) // => 10// Promiseawait Promise.allProperties({  a: Promise.resolve(1),  b: Promise.resolve(2),}) // => { a: 1, b: 2 }await Promise.allPropertiesSettled({  a: Promise.resolve(1),  b: Promise.reject(2)}) // => {//   a: { status: 'fulfilled', value: 1 },//   b: { status: 'rejected', reason: 2 }// }// String'hello'.reverse() // => "olleh"'racecar'.isPalindrome() // => true'0x01'.isNumeric() // => true'polyfull'.equalsIgnoreCase('POLYFULL') // => true// And Many Many Others!!

Remember to leave a if you like it!

https://github.com/GiovanniCardamone/polyfull


Original Link: https://dev.to/giovannicardamone/polyfull-enhance-js-functionalities-3bo

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To