in

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)
Enter fullscreen mode

Exit fullscreen mode

and if you have to remove each occurence of that element can be even worst:

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

Exit fullscreen mode

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

someArray.remove(someElement)
Enter fullscreen mode

Exit fullscreen mode

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'
Enter fullscreen mode

Exit fullscreen mode

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!!
Enter fullscreen mode

Exit fullscreen mode

Remember to leave a ⭐ if you like it!

https://github.com/GiovanniCardamone/polyfull



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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Mēris Botnet Hit Russia’s Yandex With Massive 22 Million RPS DDoS Attack

Automated Security Testing For REST API’s