silveress_custom
v3.0.20
Published
Custom functions that I have found useful
Downloads
234
Readme
Intro
My package for custom functions
Functions
Table of Contents
- moduleTest
- cleanQuery
- convertDate
- IsJsonString
- bumpRequests
- capitalize
- createRandomString
- convertToGold
- beautifyJSON
- sorter
- stringToNumber
- uniq
- getNextUpdate
- filterGeneralNumber
- filterGeneralText
- getURL
- verifySession
- createUniqueSession
- sendPageView
- logToDB
- dataToDbArray
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
queryobject to clean up
Returns object cleaned query
convertDate
Converts date to another format
Parameters
Returns string converted date
IsJsonString
Checks if a particular string is json or not
Parameters
itemobject that you want to test
Returns boolean if the input is json or not
bumpRequests
Just capitalises the first letter of a string
Parameters
Returns object same format as the input object
capitalize
Just capitalises the first letter of a string
Parameters
strstring imput string
Returns string capitalised string.
createRandomString
Creates a random string of specified length
Parameters
lengthnumber Input number (optional, default50)
Returns string random string.
convertToGold
Converts a number to g/s/c format
Mostly used for GuildWars2
Parameters
Returns string formatted g/s/c.
beautifyJSON
This beautifies json depending on teh flag
Parameters
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
inputnumber
Returns number Resulting number.
uniq
Returns an array of unique objects
Parameters
arrayarray of the account
Returns array Unique items.
getNextUpdate
For Datawars2
Gets the next update based on the users level
Parameters
levelstring of the accountnewAccountboolean is it a new accountmappingobject 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
itemstring item being filteredfilterstring what the item is being filtered bymultipliernumber 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
Returns boolean returns true or false.
getURL
This function gets the specified url with options
Requires:
- request-promise-native
Parameters
rpobject request-promise-native objecturlstring url ye are requestingoptionsobject? optional options
Returns object with headers, body and errors.
verifySession
Verifies sessionKey
Requires:
- mongodb
Parameters
dbobject Mongodb instancecollectionstring Collection that you want to store the session data in (optional, defaultaccounts_sessions)sessionstring user that the key is being generated forreqobject request object
Returns string sessionKey.
createUniqueSession
Creates a sessionKey
Requires:
- mongodb
Parameters
dbobject Mongodb instancecollectionstring Collection that you want to store the session data in (optional, defaultaccounts_sessions)userstring user that the key is being generated forreqobject request objectsessionKeystring? 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
uaobject universal-analyticsuuidobject uuid-by-stringreqobject page request objectgastring the GA code
Returns boolean
logToDB
Logs the specified message into the DB
Requires:
- mongodb
Parameters
dbobject mongodb objectlogCollectionstring? collection to put it intotypestring categorylocationstring subcategorymessagestring main messagemiscobject? object that contains other messagesconsoleFlagboolean? log to consolemaxSizenumber? size of collection
Returns null
dataToDbArray
Takes an array of objects and returns an object to insert them into a database
Parameters
dataarray array of objectslimitnumber? maximum amount to insert in one goaccessorstring? accessor for the find querysetOnInsertobject? accessor for the find query
Returns object
Functions_ext
Table of Contents
- getURL
- verifySession
- createUniqueSession
- sendPageView
- moduleTest
- cleanQuery
- convertDate
- IsJsonString
- bumpRequests
- capitalize
- createRandomString
- convertToGold
- beautifyJSON
- sorter
- stringToNumber
- uniq
- getNextUpdate
- filterGeneralNumber
- filterGeneralText
getURL
This function gets the specified url with options
Requires:
- request-promise-native
Parameters
rpobject request-promise-native objecturlstring url ye are requestingoptionsobject optional options
Returns object with headers, body and errors.
verifySession
Verifies sessionKey
Requires:
- mongodb
Parameters
dbobject Mongodb instancecollectionstring Collection that you want to store the session data in (optional, defaultaccounts_sessions)sessionstring user that the key is being generated forreqobject request object
Returns string sessionKey.
createUniqueSession
Creates a sessionKey
Requires:
- mongodb
Parameters
dbobject Mongodb instancecollectionstring Collection that you want to store the session data in (optional, defaultaccounts_sessions)userstring user that the key is being generated forreqobject request object
Returns string sessionKey.
sendPageView
This function gets sends a page view to google analytics
Requires:
- universal-analytics
- uuid-by-string
Parameters
uaobject universal-analyticsuuidobject uuid-by-stringreqobject page request objectgastring the GA code
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
queryobject to clean up
Returns object cleaned query
convertDate
Converts date to another format
Parameters
Returns string converted date
IsJsonString
Checks if a particular string is json or not
Parameters
itemobject that you want to test
Returns boolean if the input is json or not
bumpRequests
Just capitalises the first letter of a string
Parameters
Returns object same format as the input object
capitalize
Just capitalises the first letter of a string
Parameters
strstring imput string
Returns string capitalised string.
createRandomString
Creates a random string of specified length
Parameters
lengthnumber Input number (optional, default50)
Returns string random string.
convertToGold
Converts a number to g/s/c format
Mostly used for GuildWars2
Parameters
Returns string formatted g/s/c.
beautifyJSON
This beautifies json depending on teh flag
Parameters
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
inputnumber
Returns number Resulting number.
uniq
Returns an array of unique objects
Parameters
arrayarray of the account
Returns array Unique items.
getNextUpdate
For Datawars2
Gets the next update based on the users level
Parameters
levelstring of the accountnewAccountboolean is it a new accountmappingobject 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
itemstring item being filteredfilterstring what the item is being filtered bymultipliernumber 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
Returns boolean returns true or false.
