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
-
query
object 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
-
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
Returns object same format as the input object
capitalize
Just capitalises the first letter of a string
Parameters
-
str
string imput string
Returns string capitalised string.
createRandomString
Creates a random string of specified length
Parameters
-
length
number 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
-
input
number
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
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, defaultaccounts_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, defaultaccounts_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
-
ua
object universal-analytics -
uuid
object uuid-by-string -
req
object page request object -
ga
string the GA code
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
- 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
-
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, defaultaccounts_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, defaultaccounts_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
-
ua
object universal-analytics -
uuid
object uuid-by-string -
req
object page request object -
ga
string 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
-
query
object 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
-
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
Returns object same format as the input object
capitalize
Just capitalises the first letter of a string
Parameters
-
str
string imput string
Returns string capitalised string.
createRandomString
Creates a random string of specified length
Parameters
-
length
number 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
-
input
number
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
Returns boolean returns true or false.