@appngo-sk/extensions
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Extensions for TypeScript / JavaScript

Extension methods for built-in objects in javascript with typescript support.

String

  • getDateFromISO()

getDateFromISO()

Gets date part (YYYY-MM-DD) of the ISO formatted date string.

const date = new Date()
const iso = date.toISOString()

iso.getDateFromISO() // returns date in YYYY-MM-DD format

Array

  • isEmpty()
  • areEmpty()
  • isNotEmpty()
  • areNotEmpty()
  • excluding(...items)

isEmpty()

Returns true if the array is empty.

Example

const collection = []

collection.isEmpty() // returns true
[1].isEmpty() // returns false

areEmpty()

Alias for isEmpty().

Example

const types = [1, 2, 3]

types.areEmpty() // returns true

isNotEmpty()

Negated isEmpty().

areNotEmpty()

Alias for isNotEmpty()

excluding(...items)

Returns an array without the specified items.

Example

const arr = [1, 2, 3]

arr.excluding(2) // returns [1, 3]
arr.excluding(1, 3) // returns [2]

Number

  • isBetween(x, y)

isBetween(x, y)

Returns true if the number is between specified number range (inclusive).

Example

const num = 2

num.isBetween(1, 3) // returns true
num.isBetween(3, 1) // returns true as well

Behind the scenes

Defined non-iterable properties on prototypes

Object.defineProperties(Array.prototype, {
    property1: function() {
        // this refers to the current object instance of the prototype
        // if function keyword is used to create the function
        return this
    }
})

Defined types in the global scope

declare global {
    interface Array<T> {
        property1(): Array
    }
}

Readme

Keywords

Package Sidebar

Install

npm i @appngo-sk/extensions

Weekly Downloads

2

Version

1.0.5

License

ISC

Unpacked Size

5.38 kB

Total Files

11

Last publish

Collaborators

  • simonhrmo
  • romanstrazanec