2.0.3 • Published 2 years ago

js-utils-julseb v2.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

JS utils

Small JavaScript functions

allCities

JSON file with all cities and countries in the world. Structure:

{
    "country": "Germany",
    "name": "Berlin"
},

calculateTotalSum

Calculates the total sum of an array of numbers

calculateTotalSum([3, 30, 42, 2]) # 77

capitalize

Capitalizes the first letter of a string

capitalize("hello") # Hello

convertDate

Converts a date in the format yyyy-mm-dd to dd fullMonth yyyy

convertDate("2022-01-28") # 28 January 2022

convertDateShort

Converts a date in the format yyyy-mm-dd to dd shortMonth yyyy

convertDateShort("2022-01-28") # 28 Jan 2022

convertToEmail

Converts a string to an email address. You can also specify the domain name

convertToEmail("Julien Sebag") # julien.sebag@email.com
convertToEmail("Julien Sebag", "me.com") # julien.sebag@me.com

convertToPascal

Converts a string to PascalCase

convertToPascal("hello world") # HelloWorld

convertYoutube

Converts a YouTube url to an embed link for iframes

convertYoutube("https://www.youtube.com/watch?v=2EaxYi31ips") # https://www.youtube.com/embed/2EaxYi31ips

convertPrice

Converts an amount to a formatted price

convertPrice(1000, "EUR") # 1 000,00 €

detectLanguage

Search for lang or language in localStorage, and if it returns null both times detects the browser language

detectLanguage() # "fr"

getFirstName

Returns the first name of a string

getFirstName("Julien Sebag") # Julien

getLastName

Returns the last name of a string

getLasttName("Julien Sebag") # Sebag

getRandom

Returns a random value inside an array

getRandom(["Hello", "world", "how", "are", "you"]) # how

getRandomAvatar

Returns a random avatar from cartoon-avatar library. Can be male, female, or other for random gender.

getRandomAvatar("male") # https://raw.githubusercontent.com/Ashwinvalento/cartoon-avatar/master/lib/images/male/86.png

getRandomCity

Returns a random city from a specified country

getRandomCity("France") # Nîmes, France

getRandomDate

Returns a random date. You need to specify the minimum and maximum year

getRandomDate(1970, 2022) # 1989-03-12

getRandomLocation

Returns a random location from the allCities JSON file

getRandomLocation() # Ailsworth, United Kingdom

getRandomNumber

Returns a random number in a range. You need to specify the min and max

getRandomNumber(1, 20) # 12

getRandomString

Returns a random string of letters and numbers. You need to specify the length

getRandomString(20) # ad98W9OYNHbBZt6xdz5T

getRandomTime

Returns a random time. You need to specify the min hour and max hour.

getRandomTime(0, 23) # 10:24

getTimeNow

Returns the time

getTimeNow() # 14:42

getToday

Returns today's date

2022-03-07

passwordRegex

Tests if a password contains at least 6 characters, one number, one uppercase letter and one lowercase letter

passwordRegex.test("Password42") # true

emailRegex

Tests if an email address is valid

emailRegex.test("a@b.c") # false

scrollToTop

Function to scroll to the top of the page on click

slugify

Replaces accents, spaces, uppercase letters, etc., in a string to convert it to a url friendly string

slugify("Hello world how are you?") # hello-world-how-are-you

stringifyPx

Returns a value in pixels if you enter a number

stringifyPx(80) # 80px

unslugify

Replaces dashes and underscores to a space, and capitalize the first letter of a string

unslugify("hello-world-how-are-you") # Hello world how are you
1.0.19

2 years ago

1.0.18

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

2.0.1

2 years ago

1.0.24

2 years ago

2.0.0

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.30

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago