@pangenerator/utils

A collection of snippets for creative coding

Usage no npm install needed!

<script type="module">
  import pangeneratorUtils from 'https://cdn.skypack.dev/@pangenerator/utils';
</script>

README

Version Tests Dependencies Dev Dependencies

utils

Various functions used in javascript tools


utils.map(value, low1, high1, low2, high2) ⇒ Number

Map a number from one range to another

Kind: static method of utils
Returns: Number - Mapped number
Params

  • value Number - Number to map
  • low1 Number - Source range lower bound
  • high1 Number - Source range upper bound
  • low2 Number - Target range lower bound
  • high2 Number - Target range upper bound

utils.clamp(value, min, max) ⇒ Number

Clamp a number to range

Kind: static method of utils
Returns: Number - Clamped number
Params

  • value Number - Number to clamp
  • min Number - Range lower bound
  • max Number - Range upper bound

utils.norm(value, start, stop) ⇒ Number

Normalize a number

Kind: static method of utils
Returns: Number - normalized number (0.0 - 1.0)
Params

  • value Number - value to normalize
  • start Number - Source range lower bound
  • stop Number - Source range upper bound

utils.random([low], high) ⇒ Number

Generate random number from range

Kind: static method of utils
Returns: Number - Random number
Params

  • [low] Number - Range lower bound
  • high Number - Range upper bound

utils.randomDir() ⇒ Number

Generate random direction (-1 or 1)

Kind: static method of utils
Returns: Number - Random direction


utils.lerp(start, stop, amt) ⇒ Number

Linear interpolation

Kind: static method of utils
Returns: Number - Interpolated value
Params

  • start Number - First value
  • stop Number - Second value
  • amt Number - amount to interpolate

utils.lerp3(A, B, amt) ⇒ Point

Linear interpolation in 3D

Kind: static method of utils
Returns: Point - Interpolated point
Params

  • A Point - First point
  • B Point - Second point
  • amt Number - amount to interpolate

utils.lerpedPoints(A, B, count) ⇒ Array.<Point>

Linear interpolation in 3D array

Kind: static method of utils
Returns: Array.<Point> - Interpolated points
Params

  • A Point - First point
  • B Point - Second point
  • count Number - Point count

utils.square(a) ⇒ Number

Square

Kind: static method of utils
Returns: Number - squared number
Params

  • a Number - Number to square

utils.dist(A, B) ⇒ Number

Distance between two points (2D and 3D)

Kind: static method of utils
Returns: Number - distance between the points
Params

  • A Point - First point
  • B Point - Second point

utils.degrees(radians) ⇒ Number

Convert angle in radians to degrees

Kind: static method of utils
Returns: Number - angle in degrees
Params

  • radians Number - angle in radians

utils.radians(degrees) ⇒ Number

Convert angle in degrees to radians

Kind: static method of utils
Returns: Number - angle in radians
Params

  • degrees Number - angle in degrees

utils.intersection(c1, c2) ⇒ Array | Boolean

Find intersection points between two circles

Kind: static method of utils
Returns: Array | Boolean - intersection or false (if no intersection)
Params

  • c1 Circle - first circle
  • c2 Circle - second circle

utils.randomName(N) ⇒ String

Generate random name

Kind: static method of utils
Returns: String - random name
Params

  • N Number - length of the name

utils.timestampName() ⇒ String

Generate timestamp name

Kind: static method of utils
Returns: String - timestamp name


utils.randomIndex(N) ⇒ Number

Generate random name

Kind: static method of utils
Returns: Number - random index
Params

  • N Number - max index

utils.copyArray(source) ⇒ Array

Copy array

Kind: static method of utils
Returns: Array - array copy
Params

  • source Array - source array

utils.shuffleArray(source) ⇒ Array

Shuffle array

Kind: static method of utils
Returns: Array - shuffled array copy
Params

  • source Array - source array

utils.filterUnique(source) ⇒ Array

Filter array unique

Kind: static method of utils
Returns: Array - array with unique elements only
Params

  • source Array - source array

utils.lerpColor(a, b, amt) ⇒ String

Linear color interpolation

Kind: static method of utils
Returns: String - Interpolated color
Params

  • a String - First color
  • b String - Second color
  • amt Number - amount to interpolate

utils.precision(value, precision) ⇒ Number

Round number to precision

Kind: static method of utils
Returns: Number - rounded number
Params

  • value Number - value to round
  • precision Number - decimal places

utils.loadJSON(address, callback)

Load JSON

Kind: static method of utils
Params

  • address String - address of JSON to load
  • callback function - function to call on result

utils.removeDiacritics(str) ⇒ String

Remove polish diacritics

Kind: static method of utils
Returns: String - string without diacritics
Params

  • str String - string with diacritics

utils.splitChunks(str, n, discard) ⇒ Array

Split string to N sized chunks

Kind: static method of utils
Returns: Array - array of string chunks
Params

  • str String - string to split
  • n Number - chunk length
  • discard Boolean - discard chunks shorter than N

utils.getQuarter(d) ⇒ Array

Get quarter from date

Kind: static method of utils
Returns: Array - year and quarter (1-4)
Params

  • d Date - Date to get quarter from

utils.quarterExtent(quarter, year) ⇒ Array

Get quarter extent

Kind: static method of utils
Returns: Array - start and end date of quarter
Params

  • quarter Number - quarter (1-4)
  • year Number - full year

utils.downloadDataUri(options)

Download file from base64 data uri

Kind: static method of utils
Params

  • options Object - options for the downloaded file
    • .data String - contents of the file
    • .filename String - name of the file

utils.polarToCartesian(r, angle) ⇒ Point

Convert coordinates from polar to cartesian

Kind: static method of utils
Returns: Point - cartesian coordinates
Params

  • r Number - radius
  • angle Number - angle

utils.cartesianToPolar(x, y) ⇒ Object

Convert coordinates from cartesian to polar

Kind: static method of utils
Returns: Object - polar coordinates
Params

  • x Number - x coordinate
  • y Number - y coordinate

utils.pageOffset(elem) ⇒ Object

Get element page offset

Kind: static method of utils
Returns: Object - top and left page offset
Params

  • elem Object - HTML element

utils.fuzzySearch(list, searchValue) ⇒ Array

Fuzzy search element in list

Kind: static method of utils
Returns: Array - elements matching search value
Params

  • list Array - Array of terms
  • searchValue String - search value to find

utils~Point : Object

Kind: inner typedef of utils
Properties

  • x Number - x coordinate
  • y Number - y coordinate
  • z Number - z coordinate

utils~Circle : Object

Kind: inner typedef of utils
Properties

  • x Number - x coordinate of the center point
  • y Number - y coordinate of the center point
  • r Number - radius

Copyright © 2022 panGenerator