@pangenerator/utils

2.8.7 • Public • Published

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.removeNonAlphaNumeric(str) ⇒ String

Remove all non alphanumeric characters

Kind: static method of utils
Returns: String - string without non alphanumeric characters
Params

  • str String - string with non alphanumeric characters

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.datesBetween(start, end) ⇒ Array

Get all dates between two dates

Kind: static method of utils
Returns: Array - all dates between start and end
Params

  • start Date - start date
  • end Date - end date

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.dist2(A, B) ⇒ Number

Distance between two points (2D and 3D) squared

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

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

utils.distToSegment2(A, S, E) ⇒ Number

Distance between point and segment squared

Kind: static method of utils
Returns: Number - squared distance between the point and the segment
Params

  • A Point - First point
  • S Point - Segment start
  • E Point - Segment end

utils.distToSegment(A, S, E) ⇒ Number

Distance between point and segment

Kind: static method of utils
Returns: Number - distance between the point and the segment
Params

  • A Point - First point
  • S Point - Segment start
  • E Point - Segment end

utils.sepCase(str) ⇒ string

Convert string to custom separator case

Kind: static method of utils
Returns: string - custom cased string
Params

  • str string - string to convert

utils.snakeCase(str) ⇒ string

Convert string to snake case

Kind: static method of utils
Returns: string - snake cased string
Params

  • str string - string to convert

utils.kebabCase(str) ⇒ string

Convert string to kebab case

Kind: static method of utils
Returns: string - kebab cased string
Params

  • str string - string to convert

utils.camelCase(str) ⇒ string

Convert string to camel case

Kind: static method of utils
Returns: string - camel cased string
Params

  • str string - string to convert

utils.contains(elem, arr) ⇒ boolean

Check if array contains

Kind: static method of utils
Returns: boolean - - true when element is in array
Params

  • elem any - element to find in array
  • arr Array - array to look in

utils.getCSS(parentElement) ⇒ string

Get CSS Styles from element

Kind: static method of utils
Returns: string - - extracted CSS
Params

  • parentElement HTMLElement - Element to get styles from

utils.appendCSS(cssText, element)

Append CSS to element

Kind: static method of utils
Params

  • cssText string - CSS text to append
  • element HTMLElement - element to append CSS to

utils.getSVGString(svgNode) ⇒ string

Get SVG string from node

Kind: static method of utils
Returns: string - - svg as string
Params

  • svgNode HTMLElement - svg node to get text from

utils.svgStringToImage(svgString, width, height, format, transparent, callback)

Convert SVG string to image and call the callback

Kind: static method of utils
Params

  • svgString string - SVG string to convert
  • width Number - width of output image
  • height Number - height of output image
  • format string - format of output image
  • transparent boolean - transparency flag
  • callback function - function to call when ready

utils.svgToUri(svgNode) ⇒ string

Convert SVG to data uri

Kind: static method of utils
Returns: string - - uri data scheme string
Params

  • svgNode HTMLElement - SVG element to get uri from

utils.shallowCopyExcluding(obj, prop) ⇒ Object

Copy object excluding property

Kind: static method of utils
Returns: Object - - copied object
Params

  • obj Object - Object to copy
  • prop string - property name

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 © 2023 panGenerator

Readme

Keywords

Package Sidebar

Install

npm i @pangenerator/utils

Weekly Downloads

16

Version

2.8.7

License

MIT

Unpacked Size

34 kB

Total Files

4

Last publish

Collaborators

  • jkozniewski
  • kgolinski