Skip to content

A package that provides functions based on ruby language methods by adding them to Array, String and Number prototypes.

Notifications You must be signed in to change notification settings

lionffl/rb-methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rb-methods

Installation

npm install rb-methods --save

Usage

import 'rb-methods' or require('rb-methods')

Examples:

import "rb-methods"

const numbers = [1, 4, 5, 6]
const foo = "foo"
const one = 1
const two = 2
const phrase = "this is a phrase"
const seven = 7

const max = numbers.max
console.log(max)
// output: 6

const min = numbers.min
console.log(min)
// output: 1

const average = numbers.average
console.log(average)
// output: 4

const sum = numbers.sum
console.log(sum)
// output: 16

console.log(one.isEven)
// output: false 
console.log(one.isOdd)
// output: true

console.log(foo.first)
// output: "f"

console.log(seven.isPrime)
// output: true

console.log(one.isPrime)
// output: undefined

console.log(phrase.capitalize)
// output: This Is A Phrase

console.log(numbers.empty)
// output: false

Disclaimer

Be aware that modifying built-in JavaScript objects like strings, arrays etc it is not considered a good practice. Use it at your own risk.

About

A package that provides functions based on ruby language methods by adding them to Array, String and Number prototypes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published