Congrats on the ultrawide 😉

smoke-machine-js

smoke-signal-js

smoke-machine-js

A collection of helpful functions, polyfills, and definitions I frequently use in my projects.

Contains general content, as well as project-specific code snippets which is implemented in multiple contexts.

This package is intended primarily for personal use, but please feel free to use/improve any of the functions provided here.

Installation

npm install smoke-machine-js

Usage

// For ES6 imports
import { helperFunctions } from 'smoke-machine-js';

// For commonJS
const { helperFunctions } = require('smoke-machine-js');

Documentation

Documentation for all modules. GitHub | NPM | View on Website | Donate

Helper Functions

A collection of functions for processing and formatting data.

Some of these may be redundant, depending on their runtime (e.g. helperFunctions.getTime() in a browser with the Internationalization API). These functions are mostly meant to act as polyfills for runtimes where they are not natively supported.

Many of these functions are extremely simple (e.g. helperFunctions.arrayRandom(arr)), and you may ask yourself why they require a function. The reason is that I do not feel like writing it 200,000 times, or the underlying code isn't nearly as semantic as a named function.


helperFunctions.stringToSHA256(str) ⇒

Kind: static method of helperFunctions
Returns: ByteBuffer containing SHA256 encoded str

Param Type
str string

helperFunctions.stringToByteBuffer(str) ⇒

Kind: static method of helperFunctions
Returns: Byte Array containing encoded str

Param Type
str string

helperFunctions.intFromBytes(bytearray) ⇒

Kind: static method of helperFunctions
Returns: Decoded 64-bit Floating Point number

Param Type
bytearray bytearray

helperFunctions.roundFloat(float) ⇒

Useful for rounding single-precision floats (such as those encoded in a Java application)

Kind: static method of helperFunctions
Returns: Number rounded to the 100ths place.

Param Type
float number

helperFunctions.getTime(full) ⇒

Kind: static method of helperFunctions
Returns: Formatted string time

Param Type Default Description
full boolean false Whether or not function returns seconds. default: false.

helperFunctions.projectAudit()

Iterates over all files (excluding node_modules and the like) to determine the (roughly estimated) number of lines of code in a given project

Kind: static method of helperFunctions

helperFunctions.crc32(str) ⇒

Generates a crc32 checksum from a string

Kind: static method of helperFunctions
Returns: crc32 checksum number

Param Type Description
str string The stringified data to be converted.

helperFunctions.parsedJsonStringsToInt(object) ⇒

Takes a parsed JSON object which contains numbers read as strings and converts those strings to numbers. e.g. userID: "1234" would become userID: 1234. Also has the nasty tendency to turn empty arrays into zeroes.

Kind: static method of helperFunctions
Returns: Object with numbers, rather than strings.

Param Type Description
object object The stringified data to be converted.

helperFunctions.degreesToRadians(deg)

Converts degrees to radians. Simple as.

Kind: static method of helperFunctions

Param Type
deg number

helperFunctions.radiansToDegrees(rad)

Converts radians to degrees. Simple as.

Kind: static method of helperFunctions

Param Type
rad number

helperFunctions.milesToKilometers(miles)

Converts miles to kilometers. Simple as.

Kind: static method of helperFunctions

Param Type
miles number

helperFunctions.kilometersToMiles(kilometers)

Converts kilometers to miles. Simple as.

Kind: static method of helperFunctions

Param Type
kilometers number

helperFunctions.bytesToHexString(data, length)

Converts a byte array into a hexadecimal string.

Kind: static method of helperFunctions

Param Type Default Description
data bytearray Data to be encoded
length number 32 The maximum number of bytes which will be read (left justified). Default: 32.

helperFunctions.arrayRandom(arr)

Selects a pseudorandom value from the provided array. Because I was sick of typing 'Math.' 200 times.

Kind: static method of helperFunctions

Param Type Description
arr array Array to be selected from.

helperFunctions.capitalizeString(str)

Capitalizes a given string.

Kind: static method of helperFunctions

Param Type Description
str string String to be capitalized

helperFunctions.generateOrdinal(i) ⇒

Generates an ordinal suffix for a number. e.g. 1 becomes 1st, 9 becomes 9th.

Kind: static method of helperFunctions
Returns: The number concatenated with its ordinal.

Param Type Description
i number The number for which an ordinal will be generated.

helperFunctions.removeMarkdownTags(str) ⇒

Coarsely removes markdown tags from a string. e.g. Hello world becomes Hello world

Kind: static method of helperFunctions
Returns: The number without markdown tags

Param Type Description
str string The string with Markdown formatting

helperFunctions.camelCase(str) ⇒

Formats a string to camelCase e.g. Hello World becomes helloWorld.

Kind: static method of helperFunctions
Returns: camelCase string

Param Type
str string

Launch Functions

A collection of functions specific to Launch-related projects:

  • Launch
  • Launch II
  • Launch: Experimental
  • Counterforce
  • Counterforce II
  • smokeSignal

launchFunctions.stringFromData(bb) ⇒

Reads a Short at the provided ByteBuffer's offset, reads a string of the length denoted by the read short. This DOES iterate the ByteBuffer in the namespace where the function is called.

Kind: static method of launchFunctions
Returns: The string which was read.

Param Type Description
bb ByteBuffer The ByteBuffer from which the string will be read.

launchFunctions.getStringData(str) ⇒

Converts a string to a ByteBuffer containing a short (representing the length of the converted string), followed by the converted string.

Kind: static method of launchFunctions
Returns: ByteArray

Param Type Description
str string The string which will be converted.

launchFunctions.getStringDataSize(str) ⇒

Returns the byte-size of a short (representing the length of the string), followed by a byte-encoded string

Kind: static method of launchFunctions
Returns: Number

Param Type Description
str string The string which will be measured.

launchFunctions.sanitizeName(str) ⇒

Sanitized the given name for profanity, as well as dangerous characters. Not currently functional.

Kind: static method of launchFunctions
Returns: The sanitized string.

Param Type Description
str string The string which will be sanitized.

launchFunctions.cleanJSONGameSave(json) ⇒

Cleans coarsely converted JSON game save (from XML) for use in Counterforce. This is an ultra-specific function for Counterforce.

Kind: static method of launchFunctions
Returns: Cleaned object.

Param Type Description
json object The parsed JSON object.

Dependencies

Huge shout-out to bytebuffer.js. This package powers several of my projects and is phenomenal.

File dynamically retrieved from smoke-machine-js