1.0.10 • Published 3 years ago

daton-lib v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

daton-lib

Table of contents

Functional lib for easier JS usage

NPM JavaScript Style Guide

Install

npm install --save daton-lib

Usage

CUSTOM LOGS

customColorLog will log in the console custom message in color which you can set

Example:

customColorLog('Log me green', 'green')

yellLog use it if you want to log something very important, console will yell at you

Example:

yellLog('Yell at me ')

conditionLog has 3 params, first 2 are items in condition, third one is message This it will log only if condition is false

Example:

yellLog( 5, 10 , 'Will be logged' ) 
yellLog( 5, 5 , 'Not be logged' )

custom hooks

getScrollPosition

useScrollPosition

useCurrentWidth

DATES

icelandicDays - array with icleandic days mon-sun

monthNames - array with Icelandic months jan-dec

convertNumbersArrToDatesArr - recieve one arg ( array with numbers ) and returns array with object ready for graph shape

let testArray = [1,2,3,4,5,6,7]
convertNumbersArrToDatesArr(testArray)

convertDateToIcelandic - convert current date to Icelandic date. It recieve 2 params (postDate: string | Date & format: DateFormat). DateFormat can be 'DDMMYY' | 'MMDDYY' | 'MMYY' | 'DDMM'

calculateDayBeforeXDays - calculate days before today, so it recieve one param ( xDays ). Function will return Date (xDays before today).

calculateDayBeforeXDays(4) //It will return 4 days before today in date format

convertMonthsToGraphData - convert array with numbers and returns array with objects in right shape for graph

Arrays & Objects

compareIds compare two numbers & return boolean

compareIds(1, 2)

changeObjectPropAndReturnNewObject - params (object, key, value) Change property of existing object, but without mutating. This function returns new object

const testObj = {
  a: 1,
  b: 2,
  c: 3
  }
  const newObj = changeObjectPropAndReturnNewObject(testObj, 'c', 10) 
  console.log(testObj)/// {a: 1, b: 2, c: 3}
  console.log(newObj)/// {a: 1, b: 2, c: 10}

changeObjectPropAndMutateObject - 3 params (object, key, value) Change property of existing object, but without mutating. This function returns new object

const testObj = {
  a: 1,
  b: 2,
  c: 3
  }
  const newObj = changeObjectPropAndMutateObject(testObj, 'c', 10) 
  console.log(testObj)/// {a: 1, b: 2, c: 10}
  console.log(newObj)/// {a: 1, b: 2, c: 10}

splitArr - 2 params (array, size). First param is array which needs to be splited Second param is size of children array

let testArr = [1,2,3,4,5,6,7,8]
splitArr(1, 2) //Result [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ], [ 7,8 ] ]
splitArr(1, 4)// Result [ [ 1, 2, 3, 4 ], [ 5, 6, 8, 7 ] ]
splitArr(1, 5) //Result [ [ 1, 2, 3, 4, 5 ], [ 6, 8, 7 ] ]

convertArrToString - param (array)
Return string from array

const testArr = ['T', 'e', 's', 't'] 
convertArrToString(testArr) // => return Test

flipArr - param (array) Reverse items in array

License

MIT © Milan Poznan(https://github.com/Milan Poznan)

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago