silveress_custom

3.0.20 • Public • Published

Intro

pipeline status coverage report

My package for custom functions

Functions

Table of Contents

moduleTest

Testing if the module is working as planned

Returns string This is a successful test

cleanQuery

Cleans up a query object to work with my apis

Parameters

Returns object cleaned query

convertDate

Converts date to another format

Parameters

  • inputFormat string ISO date format
  • format string what you want (european/american)

Returns string converted date

IsJsonString

Checks if a particular string is json or not

Parameters

  • item object that you want to test

Returns boolean if the input is json or not

bumpRequests

Just capitalises the first letter of a string

Parameters

  • type string category that the particular request belongs to
  • requestsObject object input object

Returns object same format as the input object

capitalize

Just capitalises the first letter of a string

Parameters

Returns string capitalised string.

createRandomString

Creates a random string of specified length

Parameters

  • length number Input number (optional, default 50)

Returns string random string.

convertToGold

Converts a number to g/s/c format

Mostly used for GuildWars2

Parameters

  • number number Input number
  • shorten boolean cut off the trailing currency or not

Returns string formatted g/s/c.

beautifyJSON

This beautifies json depending on teh flag

Parameters

  • json string Input json
  • flag string Flag to expand it out or not (min/human)

Returns string Resulting json.

sorter

Function to sort array, need to pass in the strings directly

Parameters

Returns number Resulting order.

stringToNumber

Returns a number from a string

Strips out any non number characters and forces conversion

Parameters

Returns number Resulting number.

uniq

Returns an array of unique objects

Parameters

  • array array of the account

Returns array Unique items.

getNextUpdate

For Datawars2

Gets the next update based on the users level

Parameters

  • level string of the account
  • newAccount boolean is it a new account
  • mapping object an object mapping times to levels

Returns string ISO datestamp.

filterGeneralNumber

This function is a filter function for all numbers

Strips all non number characters

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by
  • multiplier number what to multiply the filter quanty by

Returns boolean returns true or false.

filterGeneralText

This function is a filter function text

Converts all inputs to lowercase

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by

Returns boolean returns true or false.

getURL

This function gets the specified url with options

Requires:

  • request-promise-native

Parameters

  • rp object request-promise-native object
  • url string url ye are requesting
  • options object? optional options

Returns object with headers, body and errors.

verifySession

Verifies sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • session string user that the key is being generated for
  • req object request object

Returns string sessionKey.

createUniqueSession

Creates a sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • user string user that the key is being generated for
  • req object request object
  • sessionKey string? sessionKey override used for testing

Returns string sessionKey.

sendPageView

This function gets sends a page view to google analytics

Requires:

  • universal-analytics
  • uuid-by-string

Parameters

Returns boolean

logToDB

Logs the specified message into the DB

Requires:

  • mongodb

Parameters

  • db object mongodb object
  • logCollection string? collection to put it into
  • type string category
  • location string subcategory
  • message string main message
  • misc object? object that contains other messages
  • consoleFlag boolean? log to console
  • maxSize number? size of collection

Returns null

dataToDbArray

Takes an array of objects and returns an object to insert them into a database

Parameters

  • data array array of objects
  • limit number? maximum amount to insert in one go
  • accessor string? accessor for the find query
  • setOnInsert object? accessor for the find query

Returns object

Functions_ext

Table of Contents

getURL

This function gets the specified url with options

Requires:

  • request-promise-native

Parameters

  • rp object request-promise-native object
  • url string url ye are requesting
  • options object optional options

Returns object with headers, body and errors.

verifySession

Verifies sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • session string user that the key is being generated for
  • req object request object

Returns string sessionKey.

createUniqueSession

Creates a sessionKey

Requires:

  • mongodb

Parameters

  • db object Mongodb instance
  • collection string Collection that you want to store the session data in (optional, default accounts_sessions)
  • user string user that the key is being generated for
  • req object request object

Returns string sessionKey.

sendPageView

This function gets sends a page view to google analytics

Requires:

  • universal-analytics
  • uuid-by-string

Parameters

Returns null

moduleTest

Testing if the module is working as planned

Returns string This is a successful test

cleanQuery

Cleans up a query object to work with my apis

Parameters

Returns object cleaned query

convertDate

Converts date to another format

Parameters

  • inputFormat string ISO date format
  • format string what you want (european/american)

Returns string converted date

IsJsonString

Checks if a particular string is json or not

Parameters

  • item object that you want to test

Returns boolean if the input is json or not

bumpRequests

Just capitalises the first letter of a string

Parameters

  • type string category that the particular request belongs to
  • requestsObject object input object

Returns object same format as the input object

capitalize

Just capitalises the first letter of a string

Parameters

Returns string capitalised string.

createRandomString

Creates a random string of specified length

Parameters

  • length number Input number (optional, default 50)

Returns string random string.

convertToGold

Converts a number to g/s/c format

Mostly used for GuildWars2

Parameters

  • number number Input number
  • shorten boolean cut off the trailing currency or not

Returns string formatted g/s/c.

beautifyJSON

This beautifies json depending on teh flag

Parameters

  • json string Input json
  • flag string Flag to expand it out or not (min/human)

Returns string Resulting json.

sorter

Function to sort array, need to pass in the strings directly

Parameters

Returns number Resulting order.

stringToNumber

Returns a number from a string

Strips out any non number characters and forces conversion

Parameters

Returns number Resulting number.

uniq

Returns an array of unique objects

Parameters

  • array array of the account

Returns array Unique items.

getNextUpdate

For Datawars2

Gets the next update based on the users level

Parameters

  • level string of the account
  • newAccount boolean is it a new account
  • mapping object an object mapping times to levels

Returns string ISO datestamp.

filterGeneralNumber

This function is a filter function for all numbers

Strips all non number characters

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by
  • multiplier number what to multiply the filter quanty by

Returns boolean returns true or false.

filterGeneralText

This function is a filter function text

Converts all inputs to lowercase

Parameters

  • item string item being filtered
  • filter string what the item is being filtered by

Returns boolean returns true or false.

Readme

Keywords

none

Package Sidebar

Install

npm i silveress_custom

Weekly Downloads

1

Version

3.0.20

License

BlueOak-1.0.0

Unpacked Size

59.1 kB

Total Files

11

Last publish

Collaborators

  • silveress_golden