v1.3.1

Simple, robust and un-opinionated utilities written in Javascript. Works on both Browser and Node.js runtime

npm i @cogoport/utils

Utilities

General utility functions used in any environment

  • camelCase(func: function, inputString: string) => string

    Converts string to camelCase

  • chunk(inputArray: array, size: number) => Array

    Divides an array into smaller chunks

  • cloneDeep(target: any) => Object

    Creates a clone of an object

  • debounce(func: function, wait: number, options: object) => Function

    Used to debounce repeated function calls

  • getByKey(object: GenericObject, path: string, defaultValue: any) => Object

    Gets the value at path of object

  • isEmpty(value: any) => Boolean

    Checks if a given value is empty

  • isFinite(value: any) => Boolean

    Checks if a number is finite

  • isNumber(value: any) => Boolean

    Checks if a value is number

  • kebabCase(inputString: string) => string

    Converts string to kebab_case

  • merge(obj: GenericObject, sources: array) => Object

    Merges multiple objects into one

  • omit(sourceObject: GenericObject, paths: union) => Object

    Omits certain properties from an object

  • pascalCase(func: function, inputString: string) => string

    Converts string to pascalCase

  • pick(sourceObject: GenericObject, paths: union) => Object

    Picks selective properties in an object

  • snakeCase(inputString: string) => string

    Converts string to snake case

  • sortBy(collection: union, iteratees: any) => array

    Sorts Collection by Given Iteratees

  • startCase(inputString: string) => string

    Converts string to start case

  • throttle(func: function, wait: number, options: object) => Function

    Throttles continuous function calls

  • toRawType(value: any) => string

    Check raw type of value

  • toWords(number: number, isInr: boolean) => string

    Converts Number into words

  • unique(array: array) => Array

    Create a duplicate-free array

  • uniqueBy(array: array, iteratee: any) => Array

    Creates a duplicate free array with custom function

  • upperCase(inputString: string) => string

    Converts string to uppercase

Browser

General Browser functions used in any environment

  • copyToClipboard(value: string) => Promise

    Copies the text to the clipboard from the target element or the value

  • deleteCookie(name: string) => Void

    Delete a cookie from browser

  • getCookie(name: string) => string

    Get the value of a cookie from browser

  • isBrowser(undefined) => Boolean

    This method is used to check if the window is browser or not

  • setCookie(name: string, value: any, days: number) => Void

    Set the value of a cookie in browser

Dates

General dates functions used in any environment

  • addDays(dateInput: union, num: number) => Date

    Add the specified number of days to the given date.

  • addHours(dateInput: union, num: number) => Date

    Add the specified number of hours to the given date

  • addMinutes(dateInput: union, num: number) => Date

    Add the specified number of minutes to the given date

  • compareAsc(dateLeft: union, dateRight: union) => -1|1|0

    Compare two dates in an ascending order

  • differenceInDays(dateLeft: union, dateRight: union) => Number

    Get the number of full days between the given dates.

  • endOfMonth(dateInput: union) => Date

    Gets the end of a month for the given date

  • endOfWeek(dateInput: union, options: object) => Date

    Gets the end of a week for the given date

  • format(dateInput: Date, maskInput: string, options: object, utcInput: boolean) => String

    Formats the given date according to a mask string

  • getDate(inputDate: union) => Number

    Get the day of the month of the given date.

  • getMonth(inputDate: union) => Number

    Get the month of the given date.

  • getYear(inputDate: union) => Number

    Get the year of the given date

  • isSameDay(dateLeft: union, dateRight: union) => Boolean

    Are the given dates in the same day?

  • isValid(dateInput: union) => Boolean

    Is the given date valid?

  • isYesterday(dateInput: union) => Boolean

    Is the given date yesterday?

  • startOfDay(dateInput: union) => Date

    Return the start of a day for the given date.

  • startOfMonth(dateInput: union) => Date

    Return the start of a month for the given date.

  • startOfWeek(dateInput: union, options: object) => Date

    Return the start of a week for the given date.

  • subtractDays(dateInput: union, num: number) => Date

    Subtract the specified number of days from the given date.

  • toDate(argument: union) => Date

    Convert the given argument to an instance of Date