- enableLog()
- disableLog()
- log()
- cls()
- concatFiles(filesArray)
- isFile(filePath)
- isDir(dir)
- getFilesSync(dir,ext,recurse,includeHidden)
- writeFile(filePath)
- promiseWriteFile(filePath)
- readFileToString(filePath)
- isArray(input)
- isObject(a)
- isEven(n)
- isOdd(n)
- roundTo(v,dec)
- parseObjectToObject(source,target,strict)
- cutStringTo(s,len)
- escapeHTML(str)
- getCleanJSONString(str)
- getFileExtension(filePath)
- getFileExtension2(filePath)
- getLastPartOfUrl(url)
- getRandomString(len)
- getStringBetween(str,start,end)
- getStringsBetween2(str,start,end)
- inString(needle,haystack)
- leftTrim(str,noOfChars)
- rightTrim(str,noOfChars)
- ucFirst(str)
- isEmail(email)
Information:
Enables log command globally.
Information:
Disables log command globally.
Information:
Shortcut for console.log supports logging in colors.
const aftc = require('aftc-node-tools');
const cls = aftc.cls;
const log = aftc.log;
cls();
log( ('All For The Code ' + 44).green );
log('All For The Code'.red);
log('All For The Code'.green);
log('All For The Code'.blue);
log('All For The Code'.cyan);
log('All For The Code'.yellow);
log('All For The Code'.underline.red);
log('All For The Code'.underline.green);
log('All For The Code'.inverse);
log('All For The Code'.rainbow);
log('All For The Code'.trap);
log('All For The Code'.trap.bgRed.white);
Information:
Clears the console.
cls();
Information:
Concatinates all files in the array into a string.
- Name: filesArray
Type: Array
Required: true
Info: Array of files.
Returns:
String
let files = ['file1.js','file2.js']
concatFiles(arr)
Information:
Checks if path is a file.
- Name: filePath
Type: String
Required: true
Info: Path you want to check is a file.
Returns:
Boolean
if ( isFile('./file1.js') ){
log('Its a file!')
} else {
log('That aint no file!')
}
Information:
Checks if path is a directory.
- Name: dir
Type: String
Required: true
Info: Path you want to check is a directory.
Returns:
Boolean
if ( isDir('./mydir') ){
log('It exists!')
} else {
log('Nooooo!')
}
getFilesSync(dir,ext,recurse,includeHidden)
Information:
Gets an array of files in a directory. Hidden files start with a . (linux style, not windows)
-
Name: dir
Type: Array
Required: true
Default: null
Info: Directory. -
Name: ext
Type: String
Required: true
Default: *
Info: Array of files. -
Name: recurse
Type: Boolean
Required: false
Default: false
Info: Array of files. -
Name: includeHidden
Type: Boolean
Required: false
Default: false
Info: Array of files.
Returns:
Array
let files = getFilesSync('./src', '.js', true);
Information:
Writes data to a file.
- Name: filePath
Type: String
Required: true
Info: Path to file you want to write to (will create it if it doesnt exist).
Returns:
Promise
let data = 'hello world'
writeFile('./test.txt',data)
.then((res)=>{ console.log('complete')} )
Information:
Writes data to a file but returns a promise.
- Name: filePath
Type: String
Required: true
Info: Path to file you want to write to (will create it if it doesnt exist).
Returns:
Promise
let data = 'hello world';
writeFile('./test.txt', data)
.then(() => {
log('success')
});
.catch(() => {
log('failure')
});
Information:
Returns a file as a string.
- Name: filePath
Type: String
Required: true
Info: Path to file you want read.
Returns:
String
let data = readFileToString('./test.txt');
Information:
Detects if the supplied variable is an array or not (instance of returns object).
- Name: input
Type: *
Required: true
Info: The variable to check.
Returns:
Boolean
let varIsArray = isArray(3);
Information:
Detects if the supplied variable is an object or not.
- Name: a
Type: *
Required: true
Info: The variable to check.
Returns:
Boolean
let varIsObj = isObject(3);
Information:
Detects if a number is even or not.
- Name: n
Type: Number
Required: true
Info: The number you want to check is even.
Returns:
Boolean
let answer = isEven(input);
Information:
Detects if a number is odd or not.
- Name: n
Type: Number
Required: true
Info: The number you want to check is odd.
Returns:
Boolean
let answer = isOdd(input);
Information:
Rounds a number to a specific amount of decimal places.
-
Name: v
Type: Number
Required: true
Info: The number you want to round. -
Name: dec
Type: Number
Required: true
Info: The number of decimal places you wish to round to.
Returns:
Number
let v = roundTo(3.142,1);
Information:
Parse an object into another object (good for processing arguments dynamically with strict on).
-
Name: source
Type: Object
Required: true
Info: The source object to pull values from. -
Name: target
Type: Object
Required: true
Info: The target object to push values into. -
Name: strict
Type: Boolean
Required: false
Info: To only parse indexes/params that exist in both objects.
Returns:
Boolean
let args = {
a:4
}
parseObjectToObject(arguments[0],args,true);
Information:
Returns the string but to the specified length.
-
Name: s
Type: Number
Required: true
Info: The string you want to cut. -
Name: len
Type: Number
Required: true
Info: The length (number of chars) you want returned.
Returns:
String
let answer = cutStringTo(str,5);
Information:
Escapes special characters in a string.
- Name: str
Type: String
Required: true
Info: The string you want to process.
Returns:
String
let newString = escapeHTML(str);
Information:
Cleans a JSON string.
- Name: str
Type: String
Required: true
Info: The string you want to process.
Returns:
String
let newJsonString = getCleanJSONString(jsonString);
Information:
Gets the extension of the supplied file path string.
- Name: filePath
Type: String
Required: true
Info: File path string.
Returns:
String
let ext = getFileExtension(filePath);
Information:
Gets the extension of the supplied file path string (method 2).
- Name: filePath
Type: String
Required: true
Info: File path string.
Returns:
String
let ext = getFileExtension2(filePath);
Information:
Gets the last segment of a url.
- Name: url
Type: String
Required: true
Info: URL string.
Returns:
String
let urlLastSeg = getLastPartOfUrl(url);
Information:
Returns a string to a specified length of random characters.
- Name: len
Type: Number
Required: true
Info: The number of random character you want to get.
Returns:
String
let randomString = getRandomString(256);
Information:
Returns a sub string of of a string between specified start and end characters.
-
Name: str
Type: String
Required: true
Info: The source string you want to process. -
Name: start
Type: Number
Required: true
Info: Start char position. -
Name: end
Type: Number
Required: true
Info: End char position.
Returns:
String
let result = getStringBetween('test test test',5,10);
Information:
Returns a sub string of of a string between specified start and end characters. (method 2)
-
Name: str
Type: String
Required: true
Info: The source string you want to process. -
Name: start
Type: Number
Required: true
Info: Start char position. -
Name: end
Type: Number
Required: true
Info: End char position.
Returns:
String
let result = getStringBetween('test test test',5,10);
Information:
Looks for a string inside a string.
-
Name: needle
Type: String
Required: true
Info: String to search for. -
Name: haystack
Type: String
Required: true
Info: String to search.
Returns:
Boolean
let result = getStringBetween('test test test',5,10);
Information:
Trims a string from the left.
-
Name: str
Type: String
Required: true
Info: String to trim. -
Name: noOfChars
Type: Number
Required: true
Info: Number of characters to trim off.
Returns:
String
let result = leftTrim('test test test',5);
Information:
Trims a string from the right.
-
Name: str
Type: String
Required: true
Info: String to trim. -
Name: noOfChars
Type: Number
Required: true
Info: Number of characters to trim off.
Returns:
String
let result = rightTrim('test test test',5);
Information:
Returns a string with the first character uppercase.
- Name: str
Type: String
Required: true
Info: String to trim.
Returns:
String
let UpperFirstString = ucFirst('mooo');
Information:
Checks if the supplied email is valid or not.
- Name: email
Type: String
Required: true
Info: Email to validate.
Returns:
Boolean
let isValidEmail = isEmail('[email protected]');