v1.3.2
Simple, robust and un-opinionated utilities written in Javascript. Works on both Browser and Node.js runtime
npm i @cogoport/utilsUtilities
General utility functions used in any environment
camelCase(func: function, inputString: string) => stringConverts string to camelCase
chunk(inputArray: array, size: number) => ArrayDivides an array into smaller chunks
cloneDeep(target: any) => ObjectCreates a clone of an object
debounce(func: function, wait: number, options: object) => FunctionUsed to debounce repeated function calls
getByKey(object: GenericObject, path: string, defaultValue: any) => ObjectGets the value at path of object
isEmpty(value: any) => BooleanChecks if a given value is empty
isFinite(value: any) => BooleanChecks if a number is finite
isNumber(value: any) => BooleanChecks if a value is number
kebabCase(inputString: string) => stringConverts string to kebab_case
merge(obj: GenericObject, sources: array) => ObjectMerges multiple objects into one
omit(sourceObject: GenericObject, paths: union) => ObjectOmits certain properties from an object
pascalCase(func: function, inputString: string) => stringConverts string to pascalCase
pick(sourceObject: GenericObject, paths: union) => ObjectPicks selective properties in an object
snakeCase(inputString: string) => stringConverts string to snake case
sortBy(collection: union, iteratees: any) => arraySorts Collection by Given Iteratees
startCase(inputString: string) => stringConverts string to start case
throttle(func: function, wait: number, options: object) => FunctionThrottles continuous function calls
toRawType(value: any) => stringCheck raw type of value
toWords(number: number, isInr: boolean) => stringConverts Number into words
unique(array: array) => ArrayCreate a duplicate-free array
uniqueBy(array: array, iteratee: any) => ArrayCreates a duplicate free array with custom function
upperCase(inputString: string) => stringConverts string to uppercase
Browser
General Browser functions used in any environment
copyToClipboard(value: string) => PromiseCopies the text to the clipboard from the target element or the value
deleteCookie(name: string) => VoidDelete a cookie from browser
getCookie(name: string) => stringGet the value of a cookie from browser
isBrowser(undefined) => BooleanThis method is used to check if the window is browser or not
setCookie(name: string, value: any, days: number) => VoidSet the value of a cookie in browser
Dates
General dates functions used in any environment
addDays(dateInput: union, num: number) => DateAdd the specified number of days to the given date.
addHours(dateInput: union, num: number) => DateAdd the specified number of hours to the given date
addMinutes(dateInput: union, num: number) => DateAdd the specified number of minutes to the given date
compareAsc(dateLeft: union, dateRight: union) => -1|1|0Compare two dates in an ascending order
differenceInDays(dateLeft: union, dateRight: union) => NumberGet the number of full days between the given dates.
endOfMonth(dateInput: union) => DateGets the end of a month for the given date
endOfWeek(dateInput: union, options: object) => DateGets the end of a week for the given date
format(dateInput: Date, maskInput: string, options: object, utcInput: boolean) => StringFormats the given date according to a mask string
getDate(inputDate: union) => NumberGet the day of the month of the given date.
getMonth(inputDate: union) => NumberGet the month of the given date.
getYear(inputDate: union) => NumberGet the year of the given date
isSameDay(dateLeft: union, dateRight: union) => BooleanAre the given dates in the same day?
isValid(dateInput: union) => BooleanIs the given date valid?
isYesterday(dateInput: union) => BooleanIs the given date yesterday?
startOfDay(dateInput: union) => DateReturn the start of a day for the given date.
startOfMonth(dateInput: union) => DateReturn the start of a month for the given date.
startOfWeek(dateInput: union, options: object) => DateReturn the start of a week for the given date.
subtractDays(dateInput: union, num: number) => DateSubtract the specified number of days from the given date.
toDate(argument: union) => DateConvert the given argument to an instance of Date