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 melperand then use it as follows:
import { Str } from 'melper'
const camelCase = Str.camelCase('Hello World') // helloWorldNumber
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') // 1024Num.toMs
Convert human readable string to milliseconds. This method is the opposite of the Str.prettyMs method.
import { Num } from 'melper'
Num.toMs('1min') // 60000String
Str.camelCase
Convert a string to its camelCase version.
import { Str } from 'melper'
Str.camelCase('hello-world') // helloWorldStr.capitalCase
Convert a string to its capitalCase version.
import { Str } from 'melper'
Str.capitalCase('hello-world') // Hello WorldStr.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-WorldStr.dotCase
Convert string to its dot.case version.
import { Str } from 'melper'
Str.dotCase('hello-world') // hello.worldStr.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 worldStr.pascalCase
Convert a string to its PascalCase version.
import { Str } from 'melper'
Str.pascalCase('helloWorld') // HelloWorldStr.sentenceCase
Convert string to a sentence
import { Str } from 'melper'
Str.sentenceCase('hello-world') // Hello worldStr.snakeCase
Convert a string to its snake_case version.
import { Str } from 'melper'
Str.snakeCase('helloWorld') // hello_worldStr.titleCase
Convert a string to its titleCase version.
import { Str } from 'melper'
Str.titleCase('Here is a fox') // Here Is a FoxTypes
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 // objectEverything 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()) // mapTyp.isArray
Find if the given value is an array
import { Typ } from 'melper'
Typ.isArray([1, 2, 3]) // trueTyp.isBoolean
Find if the given value is a boolean
import { Typ } from 'melper'
Typ.isBoolean(true) // trueTyp.isBuffer
Find if the given value is a buffer
import { Typ } from 'melper'
Typ.isBuffer(new Buffer()) // trueTyp.isClass
Find if the given value is a class
import { Typ } from 'melper'
Typ.isClass(class A {}) // trueTyp.isDate
Find if the given value is a date object
import { Typ } from 'melper'
Typ.isDate(new Date()) // trueTyp.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')) // trueTyp.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) // falseTyp.isFunction
Find if the given value is a function
import { Typ } from 'melper'
Typ.isFunction(function foo() {}) // trueTyp.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) // falseTyp.isNull
Find if the given value is null
import { Typ } from 'melper'
Typ.isNull(null) // trueTyp.isNumber
Find if the given value is a number
import { Typ } from 'melper'
Typ.isNumber(100) // trueTyp.isObject
Find if the given value is a plain object
import { Typ } from 'melper'
Typ.isObject({}) // trueTyp.isRegExp
Find if the given value is an regular expression
import { Typ } from 'melper'
Typ.isRegexp(/[a-z]+/) // trueTyp.isString
Find if the given value is a string
import { Typ } from 'melper'
Typ.isString('hello') // trueTyp.isUndefined
Find if the given value is undefined
import { Typ } from 'melper'
Typ.isNull(undefined) // true