This content originally appeared on DEV Community and was authored by Giovanni Cardamone
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'
// ArrayConstructor
Array.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
// DateConstructor
Date.current() // => new Date(Date.now())
// Date
new Date(0).addHours(1) // => 1970-01-01T01:00:00.000Z
new Date(0).isBefore(new Date(Date.now())) // => true
new Date(0).isAfter(new Date(Date.now())) // => false
new Date(0).diff(new Date()) // => how many ms passed from 1970? :D
// NumberConstructor
Number.random() // => -789.0123
Number.random(0) // => 789.0123
Number.random(0, 100) // => 89.0123
Number.randomInt(0) // => 42
// Number
7.0.isPrime() // => true
3.0.pow(2) // => 6
40.0.goldenRation() // => [24.72~, 15.28~]
50.0.percentage(20) // => 10
// Promise
await 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
This content originally appeared on DEV Community and was authored by Giovanni Cardamone

Giovanni Cardamone | Sciencx (2021-09-11T16:14:33+00:00) PolyFull – enhance js capabilities. Retrieved from https://www.scien.cx/2021/09/11/polyfull-enhance-js-capabilities/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.