misc.js
miscellaneous javascript functions
Installation
include misc.js in your project or add to your workflow
npm install yy-misc
API Reference
Kind: global class
- Misc
- .difference(a, b) ⇒
number
- .arrayCount(a) ⇒
object
- .arraySmallest(a) ⇒
number
- .sameSign(a, b)
- .preciseRound(num, decimals) ⇒
number
- .fontSize(text, maxWidth, [maxHeight], [fontFamily])
- .wordCount(text) ⇒
number
- .aboutEqual(test, value, percent) ⇒
boolean
- .uniqueArray(a) ⇒
Array
- .clamp(n, min, max) ⇒
number
- .difference(a, b) ⇒
number
misc.difference(a, b) ⇒ return the difference between two numbers (greater - lesser)
Kind: instance method of Misc
Param | Type |
---|---|
a | number |
b | number |
object
misc.arrayCount(a) ⇒ returns {most, least, all[]} array grouped by value
Kind: instance method of Misc
Returns: object
- {most: most, least: least, all: Array}
Param | Type |
---|---|
a | Array |
number
misc.arraySmallest(a) ⇒ finds the smallest number in an array
Kind: instance method of Misc
Param | Type |
---|---|
a | Array |
misc.sameSign(a, b)
returns whether a and b have the same sign or both equal 0
Kind: instance method of Misc
Param | Type |
---|---|
a | number |
b | number |
boolean |
number
misc.preciseRound(num, decimals) ⇒ round number to certain number of decimals
Kind: instance method of Misc
Param | Type |
---|---|
num | number |
decimals | number |
misc.fontSize(text, maxWidth, [maxHeight], [fontFamily])
calculate ideal font size
Kind: instance method of Misc
Param | Type | Description |
---|---|---|
text | string |
(use maximum-sized text) |
maxWidth | number |
|
[maxHeight] | number |
|
[fontFamily] | string |
number
misc.wordCount(text) ⇒ from: http://stackoverflow.com/questions/6543917/count-number-of-words-in-string-using-javascript
Kind: instance method of Misc
Param | Type |
---|---|
text | string |
boolean
misc.aboutEqual(test, value, percent) ⇒ returns whether the test value is about equal to the value (i.e., within the given percentage)
Kind: instance method of Misc
Param | Type |
---|---|
test | number |
value | number |
percent | number |
Array
misc.uniqueArray(a) ⇒ Removes duplicates from array and returns new array from http://stackoverflow.com/questions/9229645/remove-duplicates-from-javascript-array
Kind: instance method of Misc
Param | Type |
---|---|
a | Array |
number
misc.clamp(n, min, max) ⇒ clamps a number
Kind: instance method of Misc
Param | Type | Description |
---|---|---|
n | number |
to clamp |
min | number |
|
max | number |
Copyright (c) 2016 YOPEY YOPEY LLC - MIT License - Documented by jsdoc-to-markdown