jshelper v1.0.22
JsHelpers
Just some JsHelpers I made for myself.
npm install jshelper
Example
ES6
import JsHelper = 'jshelper';
import Objects = 'jshelper/Objects';
import { find } = 'jshelper/Objects';
var data = {
person: {
name: 'Ray Davis',
age: 23,
},
job: 'idk',
};
const _jsHelper = JsHelper.Objects.find(data, 'person.name');
const _objects = Objects.find(data, 'person.name');
const _valueFromObject = find(data, 'person.name');
console.log(`JsHelper Output: ${_jsHelper}`);
console.log(`Objects Output: ${_objects}`);
console.log(`valueFromObject Output: ${_valueFromObject}`);Non ES6
const JsHelper = require('jshelper').default;API
JsHelper
JsHelper imports everything
Objects
find
This function search the item using a nexted string path
Parameters
itemObject The object you want to search inpropertyNameString The path to the value seperated by dots (.). (optional, default'')
Returns (any | undefined) The found value or nothing
Arrays
removeDupilcates
This function will remove all dupilcates from a array
Parameters
arrayArray The array to remove dupilcates from.
Returns Array The new array
sortObjects
This function will sort an array of objects no matter the depth
Parameters
arrayArray The array to sortpropertyNameString The path to the value seperated by dots (.) (optional, default'')configObject An object containing additional setting for the function (optional, default{})
Returns Array The sorted array
filterObjects
This function will folter an array of objects no matter the depth
Parameters
arrayArray The array to filtermatchstring What you want to find (Currently only support string) Need support for number boolean and custom match functionpropertyNamestring The path to the value seperate by dotes (.) (optional, default'')configObject An object containing additional setting for the function (optional, default{})config.caseSenstring The type of case sensitive to use when sorting (optional, default'lower')
Returns Array The flitered array
find
This function search the item using a nexted string path
Parameters
itemObject The object you want to search inpropertyNameString The path to the value seperated by dots (.). (optional, default'')
Returns (any | undefined) The found value or nothing
Dates
isValid
This function returns true if date is an instanceof Date
Parameters
dateDate any object that is an instanceof Date
Returns boolean if the date is an instanceof Date
daysInMonth
This function returns the number of days in a month
Parameters
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (number | undefined) The number of days in month or undefined if date is no valid
getMonthBounds
This function returns the start and end dates of the month
Parameters
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Object | undefined) A object containing the start and end dates or nothing
getWeekBounds
This function returns the start and end dates of the week
Parameters
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Object | undefined) A object containing the start and end dates or nothing
getWeekBoundsCentered
This function returns the start and end dates of the week centered around the date
Parameters
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Object | undefined) A object containing the start and end dates or nothing
getDayBounds
This function returns the start and end dates of the day
Parameters
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Object | undefined) A object containing the start and end dates or nothing
addToDate
This function returns a new date with the additions
Parameters
configObject An object containing the fields and how much to addconfig.yearsnumber The number of years to add (optional, default0)config.monthsnumber The number of months to add (optional, default0)config.daysnumber The number of days to add (optional, default0)config.hoursnumber The number of hours to add (optional, default0)config.minutesnumber The number of minutes to add (optional, default0)config.secondsnumber The number of seconds to add (optional, default0)config.millisecondsnumber The number of milliseconds to add (optional, default0)
dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A Date with the additions or nothing
addYears
This function returns a new Date with the added years
Parameters
years(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addMonths
This function returns a new Date with the added months
Parameters
months(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addWeeks
This function returns a new Date with the added weeks
Parameters
weeks(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addDays
This function returns a new Date with the added days
Parameters
days(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addHours
This function returns a new Date with the added hours
Parameters
hours(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addMinutes
This function returns a new Date with the added minutes
Parameters
minutes(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addSeconds
This function returns a new Date with the added seconds
Parameters
seconds(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
addMilliseconds
This function returns a new Date with the added milliseconds
Parameters
milliseconds(optional, default0)dateDate any object that is an instanceof Date (optional, defaultnew Date())
Returns (Date | undefined) A new Date with the addition or nothing
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago