1.0.5 • Published 4 years ago
@appngo-sk/extensions v1.0.5
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 formatArray
isEmpty()areEmpty()isNotEmpty()areNotEmpty()excluding(...items)
isEmpty()
Returns true if the array is empty.
Example
const collection = []
collection.isEmpty() // returns true
[1].isEmpty() // returns falseareEmpty()
Alias for isEmpty().
Example
const types = [1, 2, 3]
types.areEmpty() // returns trueisNotEmpty()
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 wellBehind 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
}
}