jsh

jshelper

Just some JsHelpers I made for myself.

Showing:

Popularity

Downloads/wk

1

GitHub Stars

3

Maintenance

Last Commit

4yrs ago

Contributors

0

Package

Dependencies

0

Size (min+gzip)

1.3KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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

  • item Object The object you want to search in
  • propertyName String 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

  • array Array 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

  • array Array The array to sort
  • propertyName String The path to the value seperated by dots (.) (optional, default '')
  • config Object An object containing additional setting for the function (optional, default {})
    • config.caseSen string The type of case sensitive to use when sorting (optional, default 'lower')
    • config.asc boolean True for ascending and false for descending (optional, default true)

Returns Array The sorted array

filterObjects

This function will folter an array of objects no matter the depth

Parameters

  • array Array The array to filter
  • match string What you want to find (Currently only support string) Need support for number boolean and custom match function
  • propertyName string The path to the value seperate by dotes (.) (optional, default '')
  • config Object An object containing additional setting for the function (optional, default {})
    • config.caseSen string 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

  • item Object The object you want to search in
  • propertyName String 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

  • date Date 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

  • date Date any object that is an instanceof Date (optional, default new 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

  • date Date any object that is an instanceof Date (optional, default new 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

  • date Date any object that is an instanceof Date (optional, default new 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

  • date Date any object that is an instanceof Date (optional, default new 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

  • date Date any object that is an instanceof Date (optional, default new 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

  • config Object An object containing the fields and how much to add
    • config.years number The number of years to add (optional, default 0)
    • config.months number The number of months to add (optional, default 0)
    • config.days number The number of days to add (optional, default 0)
    • config.hours number The number of hours to add (optional, default 0)
    • config.minutes number The number of minutes to add (optional, default 0)
    • config.seconds number The number of seconds to add (optional, default 0)
    • config.milliseconds number The number of milliseconds to add (optional, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new 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, default 0)
  • date Date any object that is an instanceof Date (optional, default new Date())

Returns (Date | undefined) A new Date with the addition or nothing

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100