jspro v1.0.2
WTF JSPro is!
JSPro is nothing but JavaScript Prototypes! The publisher is too lazy to write full name that's why it's just JSPro. Whatever, it's a library of hundreds of awesome JavaScript Prototypes (you may know it as dot function) for lazy programmers. Just install the package with a little effort and leave the blames for the publisher.
Sigma rule 512
Life is not a pressure cooker, don't let the pressure get into it.
Not clear yet?
Currently you are able to use some limited prototypes. For rest of the small programs, you need to re-invent the wheel.
For example
To upper case string, you use
const name = "John"
console.log(name.toUpperCase())
// JOHNor to lower case string
const name = "JOHN"
console.log(name.toLowerCase())
// johnBut JavaScript doesn't have any built-in prototypes or functions to capitalize string. So to capitaize string you needed to write a user defined function like this
const capitalizeString = (str) => str[0].toUpperCase() + str.slice(1)
const name = "john"
console.log(capitalizeString(name));
// JohnBut using JSPro you will be able to code in JavaScript like a pro.
To capitalize string
const name = "john"
console.log(name.toCapitalCase())
// John Isn't amazing?
JSPro has hundreds of awesome prototypes like this. You don't need to reinvent the wheel again.
Table of contents
Install
Simply install from you terminal as dev-dependency
npm i -D jsproUsages
You can use JSPro as Node module as well as ES6/ESNext module. Whatever, only requiring or imporing is enough. YOU DON'T HAVE TO INITIALIZE JSPro.
Node
require("jspro")ESNext
import "jspro"Prototypes
String
toCapitaCase
Returns first character capitalized
const name = 'john'
name.toCapitalCase()
// Johnreverse
Returns reversed string
const name = 'John'
name.reverse()
// nhoJtoCamelCase
Returns camel case string
const name = 'John Doe'
name.toCamelCase()
// johnDoeslugify
Slugifies string
const name = 'Hello World'
name.slugify()
// hello-worlddec
Hexadecimal to decimal
const hex = 'a'
hex.dec()
// 10 bin
Hexadecimal to binary
const hex = 'a'
hex.bin()
// 1010
/**
* hex a = decimal 10 = binary 1010
*/Number
reverse
Reverses number
const number = 12345
number.reverse()
// 54321repeat
Repeats number
const number = 12
number.repeat(2)
// 1212bin
Decimal to binary
const number = 2
number.bin()
// 11hex
Decimal to hexadecimal
const number = 10
number.hex()
// ais_even
Returns true when number is even
const number = 2
number.is_even()
// trueis_prime
Returns true when number is prime
const number = 7
number.is_prime()
// trueis_palindromic
Returns true when number is palindromic
const number = 12321
number.is_palindromic()
// truesll
Performs shift left logical, shifts n-th bite to left
const number = 2
const biteToShift = 1
number.sll(biteToShift) // The number of bite ti be shifted, default is 1
// 4srl
Performs shift right logical, shifts n-th bite to right
const number = 6
const biteToShift = 1
number.srl(biteToShift) // The number of bite ti be shifted, default is 1
// 3Array
sort_by
Returns sorted array by object key name.
If you have an array where elements are object, you can sort this now by using sort_by prototype with passing the key as string.
const list = [
{ name: 'John' },
{ name: 'Doe' }
]
list.sort_by("name")
/*
[
{ name: 'Doe' },
{ name: 'John' }
]
*/Customization
Yes, you can load only the prototypes you need.
require("jspro/string") // string only
require("jspro/number") // number only
require("jspro/array") // array onlyBy default, all four types of prototypes will be loaded.
Contribution
Publisher
Contributors
Planning to contribute?
Seems like you are not too lazy!
Thanks for your interested. You can pull the repo from git. But you are requested to open a ticket before pushing for discussing on what you are planning to add.