npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aftc-node-tools

v0.7.18

Published

<br>

Downloads

3

Readme

AFTC NODE TOOLS v0.7.17

A collection of tools/utilities that I find useful when working with node.

Donate

Available Methods & Class's:

  • 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)

Documentation

enableLog()

Information: Enables log command globally.

disableLog()

Information: Disables log command globally.

log()

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);

cls()

Information: Clears the console.

cls();

concatFiles(filesArray)

Information: Concatinates all files in the array into a string.

Parameters:

  • Name: filesArray Type: Array Required: true Info: Array of files.

Returns: String

let files = ['file1.js','file2.js']
concatFiles(arr)

isFile(filePath)

Information: Checks if path is a file.

Parameters:

  • 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!')
}

isDir(dir)

Information: Checks if path is a directory.

Parameters:

  • 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)

Parameters:

  • 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);

writeFile(filePath)

Information: Writes data to a file.

Parameters:

  • 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')} )

promiseWriteFile(filePath)

Information: Writes data to a file but returns a promise.

Parameters:

  • 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')
   });

readFileToString(filePath)

Information: Returns a file as a string.

Parameters:

  • Name: filePath Type: String Required: true Info: Path to file you want read.

Returns: String

let data = readFileToString('./test.txt');

isArray(input)

Information: Detects if the supplied variable is an array or not (instance of returns object).

Parameters:

  • Name: input Type: * Required: true Info: The variable to check.

Returns: Boolean

let varIsArray = isArray(3);

isObject(a)

Information: Detects if the supplied variable is an object or not.

Parameters:

  • Name: a Type: * Required: true Info: The variable to check.

Returns: Boolean

let varIsObj = isObject(3);

isEven(n)

Information: Detects if a number is even or not.

Parameters:

  • Name: n Type: Number Required: true Info: The number you want to check is even.

Returns: Boolean

let answer = isEven(input);

isOdd(n)

Information: Detects if a number is odd or not.

Parameters:

  • Name: n Type: Number Required: true Info: The number you want to check is odd.

Returns: Boolean

let answer = isOdd(input);

roundTo(v,dec)

Information: Rounds a number to a specific amount of decimal places.

Parameters:

  • 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);

parseObjectToObject(source,target,strict)

Information: Parse an object into another object (good for processing arguments dynamically with strict on).

Parameters:

  • 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);

cutStringTo(s,len)

Information: Returns the string but to the specified length.

Parameters:

  • 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);

escapeHTML(str)

Information: Escapes special characters in a string.

Parameters:

  • Name: str Type: String Required: true Info: The string you want to process.

Returns: String

let newString = escapeHTML(str);

getCleanJSONString(str)

Information: Cleans a JSON string.

Parameters:

  • Name: str Type: String Required: true Info: The string you want to process.

Returns: String

let newJsonString = getCleanJSONString(jsonString);

getFileExtension(filePath)

Information: Gets the extension of the supplied file path string.

Parameters:

  • Name: filePath Type: String Required: true Info: File path string.

Returns: String

let ext = getFileExtension(filePath);

getFileExtension2(filePath)

Information: Gets the extension of the supplied file path string (method 2).

Parameters:

  • Name: filePath Type: String Required: true Info: File path string.

Returns: String

let ext = getFileExtension2(filePath);

getLastPartOfUrl(url)

Information: Gets the last segment of a url.

Parameters:

  • Name: url Type: String Required: true Info: URL string.

Returns: String

let urlLastSeg = getLastPartOfUrl(url);

getRandomString(len)

Information: Returns a string to a specified length of random characters.

Parameters:

  • Name: len Type: Number Required: true Info: The number of random character you want to get.

Returns: String

let randomString = getRandomString(256);

getStringBetween(str,start,end)

Information: Returns a sub string of of a string between specified start and end characters.

Parameters:

  • 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);

getStringsBetween2(str,start,end)

Information: Returns a sub string of of a string between specified start and end characters. (method 2)

Parameters:

  • 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);

inString(needle,haystack)

Information: Looks for a string inside a string.

Parameters:

  • 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);

leftTrim(str,noOfChars)

Information: Trims a string from the left.

Parameters:

  • 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);

rightTrim(str,noOfChars)

Information: Trims a string from the right.

Parameters:

  • 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);

ucFirst(str)

Information: Returns a string with the first character uppercase.

Parameters:

  • Name: str Type: String Required: true Info: String to trim.

Returns: String

let UpperFirstString = ucFirst('mooo');

isEmail(email)

Information: Checks if the supplied email is valid or not.

Parameters:

  • Name: email Type: String Required: true Info: Email to validate.

Returns: Boolean

let isValidEmail = isEmail('[email protected]');