datypes
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Da Daaam (Global Javascript Extended Types)

I don't even know, are there packages better

Just wanted to write mine, own

Soooo..

Types

  • $object
  • $Array
  • $string
  • $number

I gave them some methods which I use too often

Installation

npm install datypes

Or

yarn add datypes

Get Started

First we have to initialize global function $

You have to run this function in your main file only once

import initTypes from "datypes"

initTypes()

Now We can define variables

Let's do

const person = $({
  name: "Dann",
  age: 18,
  hobbies: $(["_", "_"]),
})

So what can we actually do?

person.$empty() // false
person.$forEach((value, key) => console.log(`${key} : `, value))
const cloneWithoutRefs = person.$clone()
person.$hasSome("age", "hobbies", "girlfriend") // true
person.$hasAll("age", "hobbies", "girlfriend") // false

person.hobbies.remove(0) // ["_"] removes it's element
person.hobbies.log() // logs value

Types now are global

let age: $number
let person: $object<MyInterface>

Also array method .readonly()

const arr = $([1, 2, 3]) // type - number[]
const readonlyArr = arr.readonly() // type - readonly number[]

$ArrayLength

const numbers = $.$ArrayLength(5, (i) => i) // [0, 1, 2, 3, 4]

const randomDigits = $.$ArrayLength(4, () => $.randomNumber(0, 9)) // [4, 6, 7, 1]

Changelog

v1.3.0

  • Removed static methodes from $number, $string, $object and $Array
  • Added new static methods for global function $
    • is$number (whether or not value is an instance of $number)
    • is$string (whether or not value is an instance of $string)
    • is$object (whether or not value is an instance of $object)
    • is$Array (whether or not value is an instance of $Array)
    • randomNumber (returns random number between a range)
    • $ArrayLength (returns an $Array with spec. length by custom map)

v1.2.3

  • New methods for Arrays (includesAny, includesAll, compute)
  • New methods for Strings (includesAny, includesAll, capitalizeFirst)

It's not All!

Install and check yourself!

Package Sidebar

Install

npm i datypes

Weekly Downloads

8

Version

1.3.1

License

ISC

Unpacked Size

32.1 kB

Total Files

17

Last publish

Collaborators

  • aeolz