melper v0.0.0
melper
Explore a versatile assortment of helper utility functions
This module is a powerful resource that offers a comprehensive collection of reusable utilities, eliminating the need to rewrite redundant code across multiple packages. By leveraging these utilities, developers can significantly enhance their productivity and streamline their coding process. Say goodbye to the hassle of duplicating code, as this module provides an efficient and elegant solution for promoting code reusability and maintainability. Embrace the convenience and versatility of these utilities, and take your software development to the next level.
Table of contents
- Installation
- Helpers
- number
- string
- camelCase
- capitalCase
- dashCase
- dotCase
- noCase
- pascalCase
- sentenceCase
- snakeCase
- titleCase
- capialize (Under Construction)
- encodeSymbols (Under Construction)
- escapeHTML (Under Construction)
- excerpt (Under Construction)
- generateRandom (Under Construction)
- lower (Under Construction)
- pluralize (Under Construction)
- prettyBytes (Under Construction)
- prettyMs (Under Construction)
- singularize (Under Construction)
- truncate (Under Construction)
- upper (Under Construction)
- Types
Installation
Install the package from npm registry as follows:
npm i melper
# yarn
yarn add melper
# pnpm
pnpm add melper
and then use it as follows:
import { Str } from 'melper'
const camelCase = Str.camelCase('Hello World') // helloWorld
Number
Num.format
Simple alias to
Format numbers. Simple alias to Intl.NumberFormat
import { Num } from 'melper'
Num.format(123456.789, 'de-DE', { style: 'currency', currency: 'EUR' }) // '123.456,79 €'
Num.toBytes
Convert human readable string to bytes. This method is the opposite of the Str.prettyBytes
method.
import { Num } from 'melper'
Num.toBytes('1KB') // 1024
Num.toMs
Convert human readable string to milliseconds. This method is the opposite of the Str.prettyMs
method.
import { Num } from 'melper'
Num.toMs('1min') // 60000
String
Str.camelCase
Convert a string to its camelCase
version.
import { Str } from 'melper'
Str.camelCase('hello-world') // helloWorld
Str.capitalCase
Convert a string to its capitalCase
version.
import { Str } from 'melper'
Str.capitalCase('hello-world') // Hello World
Str.dashCase
Convert a string to its dash-case
version. Optionally, you can also capitalize the first letter of each segment.
import { Str } from 'melper'
Str.dashCase('helloWorld') // hello-world
Str.dashCase('helloWorld', { capitalize: true }) // Hello-World
Str.dotCase
Convert string to its dot.case
version.
import { Str } from 'melper'
Str.dotCase('hello-world') // hello.world
Str.noCase
Remove all sorts of casing
import { Str } from 'melper'
Str.noCase('hello-world') // hello world
Str.noCase('hello_world') // hello world
Str.noCase('helloWorld') // hello world
Str.pascalCase
Convert a string to its PascalCase
version.
import { Str } from 'melper'
Str.pascalCase('helloWorld') // HelloWorld
Str.sentenceCase
Convert string to a sentence
import { Str } from 'melper'
Str.sentenceCase('hello-world') // Hello world
Str.snakeCase
Convert a string to its snake_case
version.
import { Str } from 'melper'
Str.snakeCase('helloWorld') // hello_world
Str.titleCase
Convert a string to its titleCase
version.
import { Str } from 'melper'
Str.titleCase('Here is a fox') // Here Is a Fox
Types
The types module allows distinguishing between different Javascript dataTyp. The typeof
returns the same type for many different values. For example:
typeof {} // object
typeof [] // object
typeof null // object
Everything is an object in Javascript. To have better control, you can make use of the Typ.typeOf
method.
Typ.typeOf
Returns a more accurate type for a given value.
import { Typ } from 'melper'
Typ.lookup({}) // object
Typ.lookup([]) // array
Typ.lookup(Object.create(null)) // object
Typ.lookup(null) // null
Typ.lookup(function () {}) // function
Typ.lookup(class Foo {}) // class
Typ.lookup(new Map()) // map
Typ.isArray
Find if the given value is an array
import { Typ } from 'melper'
Typ.isArray([1, 2, 3]) // true
Typ.isBoolean
Find if the given value is a boolean
import { Typ } from 'melper'
Typ.isBoolean(true) // true
Typ.isBuffer
Find if the given value is a buffer
import { Typ } from 'melper'
Typ.isBuffer(new Buffer()) // true
Typ.isClass
Find if the given value is a class
import { Typ } from 'melper'
Typ.isClass(class A {}) // true
Typ.isDate
Find if the given value is a date object
import { Typ } from 'melper'
Typ.isDate(new Date()) // true
Typ.isError
Find if the given value is an instance of the error object
import { Typ } from 'melper'
import { Exception } from 'melper'
Typ.isError(new Error('foo')) // true
Typ.isError(new Exception('foo')) // true
Typ.isFloat
Find if the given value is an float number.
import { Typ } from 'melper'
Typ.isFloat(22.1) // true
Typ.isFloat(-22.1) // true
Typ.isFloat(0.3) // true
Typ.isFloat(-0.3) // true
Typ.isFloat(22.0) // false
Typ.isFloat(-22.0) // false
Typ.isFloat(-22) // false
Typ.isFunction
Find if the given value is a function
import { Typ } from 'melper'
Typ.isFunction(function foo() {}) // true
Typ.isInteger
Find if the given value is an integer.
import { Typ } from 'melper'
Typ.isInteger(22.0) // true
Typ.isInteger(22) // true
Typ.isInteger(-1) // true
Typ.isInteger(-1.0) // true
Typ.isInteger(22.1) // false
Typ.isInteger(0.3) // false
Typ.isInteger(-0.3) // false
Typ.isNull
Find if the given value is null
import { Typ } from 'melper'
Typ.isNull(null) // true
Typ.isNumber
Find if the given value is a number
import { Typ } from 'melper'
Typ.isNumber(100) // true
Typ.isObject
Find if the given value is a plain object
import { Typ } from 'melper'
Typ.isObject({}) // true
Typ.isRegExp
Find if the given value is an regular expression
import { Typ } from 'melper'
Typ.isRegexp(/[a-z]+/) // true
Typ.isString
Find if the given value is a string
import { Typ } from 'melper'
Typ.isString('hello') // true
Typ.isUndefined
Find if the given value is undefined
import { Typ } from 'melper'
Typ.isNull(undefined) // true