@cooljs123/easyjs
v0.4.1
Published
One import with 372 small, everyday JavaScript helpers (no aliases).
Downloads
611
Maintainers
Keywords
Readme
EasyJS
GitHub: easyjs
One import with 369 small, everyday JavaScript helpers (no aliases). Written in vanilla JS with no external libraries.
Install
npm i @cooljs123/easyjsUse
const easyJS = require("@cooljs123/easyjs");
// Run once to add prototype helpers (Array/String/Object methods like .shuffle(), .toTitleCase(), .mapKeys()).
// Use this only if you want prototype sugar; it changes global prototypes.
easyJS.install();
easyJS.anyOf("tom", ["thomas", "tommy", "tom"]); // true
easyJS.normalizeString(" ToM "); // "tom"
easyJS.safeGet({ a: { b: 2 } }, "a.b", 0); // 2
easyJS.safeSet({}, "a.b", 3); // { a: { b: 3 } }Modular Imports
import { sum, uniq } from "@cooljs123/easyjs";
import shuffle from "@cooljs123/easyjs/array/shuffle";
import sumDefault from "@cooljs123/easyjs/sum";
import shuffleDefault from "@cooljs123/easyjs/shuffle";const easyJS = require("@cooljs123/easyjs");
const { sum, uniq } = require("@cooljs123/easyjs");
const shuffle = require("@cooljs123/easyjs/shuffle");Chain API
easyJS.chain([1,2,2,3])
.uniq()
.shuffle()
.take(2)
.value()Plugins
You can add custom plugins to EasyJS directly:
const easyJS = require("@cooljs123/easyjs");
const reversePlugin = (easy) => {
easy.reverse = (str) => String(str).split("").reverse().join("");
};
easyJS.use(reversePlugin);
easyJS.reverse("hello"); // "olleh"Examples (All 369 Functions)
Math
abs
// Takes numbers and returns abs.
easyJS.abs(2, 3) // 2acosDeg
// Takes numbers and returns acos deg.
easyJS.acosDeg(2, 3) // nulladd
// Takes numbers and returns add.
easyJS.add(2, 3) // 5apothemRegularPolygon
// Takes numbers and returns apothem regular polygon.
easyJS.apothemRegularPolygon(2, 3) // 9.184850993605148e-17arcLength
// Takes numbers and returns arc length.
easyJS.arcLength(2, 3) // 6areaCircle
// Takes numbers and returns area circle.
easyJS.areaCircle(2, 3) // 12.566370614359172areaEllipse
// Takes numbers and returns area ellipse.
easyJS.areaEllipse(2, 3) // 18.84955592153876areaParallelogram
// Takes numbers and returns area parallelogram.
easyJS.areaParallelogram(2, 3) // 6areaRectangle
// Takes numbers and returns area rectangle.
easyJS.areaRectangle(2, 3) // 6areaRegularPolygon
// Takes numbers and returns area regular polygon.
easyJS.areaRegularPolygon(2, 3) // 0areaRing
// Takes numbers and returns area ring.
easyJS.areaRing(2, 3) // -15.707963267948966areaSector
// Takes numbers and returns area sector.
easyJS.areaSector(2, 3) // 9areaSquare
// Takes numbers and returns area square.
easyJS.areaSquare(2, 3) // 4areaTrapezoid
// Takes numbers and returns area trapezoid.
easyJS.areaTrapezoid(2, 3) // nullareaTriangle
// Takes numbers and returns area triangle.
easyJS.areaTriangle(2, 3) // 3asinDeg
// Takes numbers and returns asin deg.
easyJS.asinDeg(2, 3) // nullatanDeg
// Takes numbers and returns atan deg.
easyJS.atanDeg(2, 3) // 63.43494882292201averageOfThree
// Takes numbers and returns average of three.
easyJS.averageOfThree(2, 3) // nullaverageOfTwo
// Takes numbers and returns average of two.
easyJS.averageOfTwo(2, 3) // 2.5avg
// Takes numbers and returns avg.
easyJS.avg(2, 3) // 2.5between
// Takes numbers and returns between.
easyJS.between(2, 3) // falsecbrt
// Takes numbers and returns cbrt.
easyJS.cbrt(2, 3) // 1.2599210498948732ceilTo
// Takes numbers and returns ceil to.
easyJS.ceilTo(2, 3) // 3ceilToMultiple
// Takes numbers and returns ceil to multiple.
easyJS.ceilToMultiple(2, 3) // 3circumferenceCircle
// Takes numbers and returns circumference circle.
easyJS.circumferenceCircle(2, 3) // 12.566370614359172circumradiusRegularPolygon
// Takes numbers and returns circumradius regular polygon.
easyJS.circumradiusRegularPolygon(2, 3) // 1.5clamp
// Takes numbers and returns clamp.
easyJS.clamp(2, 3) // nullclamp01
// Takes numbers and returns clamp 01.
easyJS.clamp01(2, 3) // 1clampAbs
// Takes numbers and returns clamp abs.
easyJS.clampAbs(2, 3) // 2clampInt
// Takes numbers and returns clamp int.
easyJS.clampInt(2, 3) // nullclampMax
// Takes numbers and returns clamp max.
easyJS.clampMax(2, 3) // 2clampMin
// Takes numbers and returns clamp min.
easyJS.clampMin(2, 3) // 3clampPercent
// Takes numbers and returns clamp percent.
easyJS.clampPercent(2, 3) // 2convertCtoF
// Takes numbers and returns convert cto f.
easyJS.convertCtoF(2, 3) // 35.6convertCtoK
// Takes numbers and returns convert cto k.
easyJS.convertCtoK(2, 3) // 275.15convertFtoC
// Takes numbers and returns convert fto c.
easyJS.convertFtoC(2, 3) // -16.666666666666668convertFtoK
// Takes numbers and returns convert fto k.
easyJS.convertFtoK(2, 3) // 256.48333333333335convertKtoC
// Takes numbers and returns convert kto c.
easyJS.convertKtoC(2, 3) // -271.15convertKtoF
// Takes numbers and returns convert kto f.
easyJS.convertKtoF(2, 3) // -456.07cosDeg
// Takes numbers and returns cos deg.
easyJS.cosDeg(2, 3) // 0.9993908270190958cube
// Takes numbers and returns cube.
easyJS.cube(2, 3) // 8degToRad
// Takes numbers and returns deg to rad.
easyJS.degToRad(2, 3) // 0.03490658503988659degToTurn
// Takes numbers and returns deg to turn.
easyJS.degToTurn(2, 3) // 0.005555555555555556denormalize
// Takes numbers and returns denormalize.
easyJS.denormalize(2, 3) // nulldiff
// Takes numbers and returns diff.
easyJS.diff(2, 3) // 1distance1D
// Takes numbers and returns distance 1d.
easyJS.distance1D(2, 3) // 1distance2D
// Takes numbers and returns distance 2d.
easyJS.distance2D(2, 3) // nulldistance3D
// Takes numbers and returns distance 3d.
easyJS.distance3D(2, 3) // nulldistancePointLine
// Takes numbers and returns distance point line.
easyJS.distancePointLine(2, 3) // nulldistancePoints
// Takes numbers and returns distance points.
easyJS.distancePoints(2, 3) // nulldivide
// Takes numbers and returns divide.
easyJS.divide(2, 3) // 0.6666666666666666dot2
// Takes numbers and returns dot 2.
easyJS.dot2(2, 3) // nulldot3
// Takes numbers and returns dot 3.
easyJS.dot3(2, 3) // nullexp
// Takes numbers and returns exp.
easyJS.exp(2, 3) // 7.38905609893065expm1
// Takes numbers and returns expm 1.
easyJS.expm1(2, 3) // 6.38905609893065factorial
// Takes numbers and returns factorial.
easyJS.factorial(2, 3) // 2fibonacci
// Takes numbers and returns fibonacci.
easyJS.fibonacci(2, 3) // 1floorTo
// Takes numbers and returns floor to.
easyJS.floorTo(2, 3) // 0floorToMultiple
// Takes numbers and returns floor to multiple.
easyJS.floorToMultiple(2, 3) // 0fromPercent
// Takes numbers and returns from percent.
easyJS.fromPercent(2, 3) // 0.06gcd
// Takes numbers and returns gcd.
easyJS.gcd(2, 3) // 1geometricMean
// Takes numbers and returns geometric mean.
easyJS.geometricMean(2, 3) // 2.449489742783178harmonicMean
// Takes numbers and returns harmonic mean.
easyJS.harmonicMean(2, 3) // 2.4000000000000004heronArea
// Takes numbers and returns heron area.
easyJS.heronArea(2, 3) // nullhypot2
// Takes numbers and returns hypot 2.
easyJS.hypot2(2, 3) // 3.6055512754639896hypot3
// Takes numbers and returns hypot 3.
easyJS.hypot3(2, 3) // nullinRangeExclusive
// Takes numbers and returns in range exclusive.
easyJS.inRangeExclusive(2, 3) // falseinRangeInclusive
// Takes numbers and returns in range inclusive.
easyJS.inRangeInclusive(2, 3) // falseisEven
// Checks if is even is true.
easyJS.isEven(2, 3) // trueisFiniteNumber
// Checks if is finite number is true.
easyJS.isFiniteNumber(2, 3) // trueisInt
// Checks if is int is true.
easyJS.isInt(2, 3) // trueisMultipleOf
// Checks if is multiple of is true.
easyJS.isMultipleOf(2, 3) // falseisNaNNumber
// Checks if is na nnumber is true.
easyJS.isNaNNumber(2, 3) // falseisNegative
// Checks if is negative is true.
easyJS.isNegative(2, 3) // falseisNumber
// Checks if is number is true.
easyJS.isNumber(2, 3) // trueisOdd
// Checks if is odd is true.
easyJS.isOdd(2, 3) // falseisPositive
// Checks if is positive is true.
easyJS.isPositive(2, 3) // trueisPowerOfTwo
// Checks if is power of two is true.
easyJS.isPowerOfTwo(2, 3) // trueisPrime
// Checks if is prime is true.
easyJS.isPrime(2, 3) // trueisZero
// Checks if is zero is true.
easyJS.isZero(2, 3) // falselawOfCosinesAngle
// Takes numbers and returns law of cosines angle.
easyJS.lawOfCosinesAngle(2, 3) // nulllawOfCosinesSide
// Takes numbers and returns law of cosines side.
easyJS.lawOfCosinesSide(2, 3) // nulllawOfSinesAngle
// Takes numbers and returns law of sines angle.
easyJS.lawOfSinesAngle(2, 3) // nulllawOfSinesSide
// Takes numbers and returns law of sines side.
easyJS.lawOfSinesSide(2, 3) // nulllcm
// Takes numbers and returns lcm.
easyJS.lcm(2, 3) // 6lerp
// Takes numbers and returns lerp.
easyJS.lerp(2, 3) // nulllerpAngleDeg
// Takes numbers and returns lerp angle deg.
easyJS.lerpAngleDeg(2, 3) // nulllerpAngleRad
// Takes numbers and returns lerp angle rad.
easyJS.lerpAngleRad(2, 3) // nulllerpClamped
// Takes numbers and returns lerp clamped.
easyJS.lerpClamped(2, 3) // nulllerpInt
// Takes numbers and returns lerp int.
easyJS.lerpInt(2, 3) // nullln1p
// Takes numbers and returns ln 1p.
easyJS.ln1p(2, 3) // 1.0986122886681096log
// Takes numbers and returns log.
easyJS.log(2, 3) // 0.6931471805599453log10
// Takes numbers and returns log 10.
easyJS.log10(2, 3) // 0.3010299956639812log2
// Takes numbers and returns log 2.
easyJS.log2(2, 3) // 1manhattan2D
// Takes numbers and returns manhattan 2d.
easyJS.manhattan2D(2, 3) // nullmanhattan3D
// Takes numbers and returns manhattan 3d.
easyJS.manhattan3D(2, 3) // nullmapRange
// Takes numbers and returns map range.
easyJS.mapRange(2, 3) // nullmax
// Takes numbers and returns max.
easyJS.max(2, 3) // 3mean
// Takes numbers and returns mean.
easyJS.mean(2, 3) // 2.5median
// Takes numbers and returns median.
easyJS.median(2, 3) // 2.5medianOfThree
// Takes numbers and returns median of three.
easyJS.medianOfThree(2, 3) // 3midpointX
// Takes numbers and returns midpoint x.
easyJS.midpointX(2, 3) // 2.5midpointY
// Takes numbers and returns midpoint y.
easyJS.midpointY(2, 3) // 2.5min
// Takes numbers and returns min.
easyJS.min(2, 3) // 2mod
// Takes numbers and returns mod.
easyJS.mod(2, 3) // 2modSafe
// Takes numbers and returns mod safe.
easyJS.modSafe(2, 3) // 2mode
// Takes numbers and returns mode.
easyJS.mode(2, 3) // 2multiply
// Takes numbers and returns multiply.
easyJS.multiply(2, 3) // 6nCr
// Takes numbers and returns n cr.
easyJS.nCr(2, 3) // 0nPr
// Takes numbers and returns n pr.
easyJS.nPr(2, 3) // 0nearEqual
// Takes numbers and returns near equal.
easyJS.nearEqual(2, 3) // falsenextPrime
// Takes numbers and returns next prime.
easyJS.nextPrime(2, 3) // 2normalize
// Takes numbers and returns normalize.
easyJS.normalize(2, 3) // nullnormalizeAngle
// Takes numbers and returns normalize angle.
easyJS.normalizeAngle(2, 3) // 2percent
// Takes numbers and returns percent.
easyJS.percent(2, 3) // 66.66666666666666percentChange
// Takes numbers and returns percent change.
easyJS.percentChange(2, 3) // 50percentOf
// Takes numbers and returns percent of.
easyJS.percentOf(2, 3) // 66.66666666666666percentile
// Takes numbers and returns percentile.
easyJS.percentile(2, 3) // 2perimeterRectangle
// Takes numbers and returns perimeter rectangle.
easyJS.perimeterRectangle(2, 3) // 10perimeterRegularPolygon
// Takes numbers and returns perimeter regular polygon.
easyJS.perimeterRegularPolygon(2, 3) // 6perimeterSquare
// Takes numbers and returns perimeter square.
easyJS.perimeterSquare(2, 3) // 8perimeterTriangle
// Takes numbers and returns perimeter triangle.
easyJS.perimeterTriangle(2, 3) // nullpingPong
// Takes numbers and returns ping pong.
easyJS.pingPong(2, 3) // 2pow
// Takes numbers and returns pow.
easyJS.pow(2, 3) // 8prevPrime
// Takes numbers and returns prev prime.
easyJS.prevPrime(2, 3) // 2pythagoras
// Takes numbers and returns pythagoras.
easyJS.pythagoras(2, 3) // 3.6055512754639896quadraticDiscriminant
// Takes numbers and returns quadratic discriminant.
easyJS.quadraticDiscriminant(2, 3) // nullquadraticRoots
// Takes numbers and returns quadratic roots.
easyJS.quadraticRoots(2, 3) // [null,null]radToDeg
// Takes numbers and returns rad to deg.
easyJS.radToDeg(2, 3) // 114.59155902616465radToTurn
// Takes numbers and returns rad to turn.
easyJS.radToTurn(2, 3) // 0.3183098861837907randomBool
// Takes numbers and returns random bool.
easyJS.randomBool() // random (example: true)randomFloat
// Takes numbers and returns random float.
easyJS.randomFloat(1, 5) // random (example: 3.27)randomGaussian
// Takes numbers and returns random gaussian.
easyJS.randomGaussian() // random (example: 1.086899378726529)randomInt
// Takes numbers and returns random int.
easyJS.randomInt(1, 3) // random (example: 1)randomSign
// Takes numbers and returns random sign.
easyJS.randomSign() // random (example: 1)ratio
// Takes numbers and returns ratio.
easyJS.ratio(2, 3) // 0.6666666666666666rms
// Takes numbers and returns rms.
easyJS.rms(2, 3) // 2.5495097567963922roundBankers
// Takes numbers and returns round bankers.
easyJS.roundBankers(2, 3) // 2roundDecimal
// Takes numbers and returns round decimal.
easyJS.roundDecimal(2, 3) // 2roundDown
// Takes numbers and returns round down.
easyJS.roundDown(2, 3) // 2roundHalfDown
// Takes numbers and returns round half down.
easyJS.roundHalfDown(2, 3) // 2roundHalfUp
// Takes numbers and returns round half up.
easyJS.roundHalfUp(2, 3) // 2roundTo
// Takes numbers and returns round to.
easyJS.roundTo(2, 3) // 2roundToMultiple
// Takes numbers and returns round to multiple.
easyJS.roundToMultiple(2, 3) // 3roundToNearest
// Takes numbers and returns round to nearest.
easyJS.roundToNearest(2, 3) // 3roundToSignificant
// Takes numbers and returns round to significant.
easyJS.roundToSignificant(2, 3) // 2roundToStep
// Takes numbers and returns round to step.
easyJS.roundToStep(2, 3) // 3roundUp
// Takes numbers and returns round up.
easyJS.roundUp(2, 3) // 2safeDivide
// Takes numbers and returns safe divide.
easyJS.safeDivide(2, 3) // 0.6666666666666666sawtoothWave
// Takes numbers and returns sawtooth wave.
easyJS.sawtoothWave(2, 3) // 0.6666666666666665sigmoid
// Takes numbers and returns sigmoid.
easyJS.sigmoid(2, 3) // 0.8807970779778823sign
// Takes numbers and returns sign.
easyJS.sign(2, 3) // 1sinDeg
// Takes numbers and returns sin deg.
easyJS.sinDeg(2, 3) // 0.03489949670250097slope
// Takes numbers and returns slope.
easyJS.slope(2, 3) // nullsmoothClamp
// Takes numbers and returns smooth clamp.
easyJS.smoothClamp(2, 3) // nullsmootherstep
// Takes numbers and returns smootherstep.
easyJS.smootherstep(2, 3) // nullsmoothstep
// Takes numbers and returns smoothstep.
easyJS.smoothstep(2, 3) // nullsmoothstep01
// Takes numbers and returns smoothstep 01.
easyJS.smoothstep01(2, 3) // 1sqrt
// Takes numbers and returns sqrt.
easyJS.sqrt(2, 3) // 1.4142135623730951square
// Takes numbers and returns square.
easyJS.square(2, 3) // 4stdDev
// Takes numbers and returns std dev.
easyJS.stdDev(2, 3) // 0stdDevSample
// Takes numbers and returns std dev sample.
easyJS.stdDevSample(2, 3) // 0step
// Takes numbers and returns step.
easyJS.step(2, 3) // 1subtract
// Takes numbers and returns subtract.
easyJS.subtract(2, 3) // -1sum
// Takes numbers and returns sum.
easyJS.sum(2, 3) // 5sumOfSquares
// Takes numbers and returns sum of squares.
easyJS.sumOfSquares(2, 3) // 13sumOfTwo
// Takes numbers and returns sum of two.
easyJS.sumOfTwo(2, 3) // 5surfaceAreaCone
// Takes numbers and returns surface area cone.
easyJS.surfaceAreaCone(2, 3) // 35.22071741263713surfaceAreaCube
// Takes numbers and returns surface area cube.
easyJS.surfaceAreaCube(2, 3) // 24surfaceAreaCylinder
// Takes numbers and returns surface area cylinder.
easyJS.surfaceAreaCylinder(2, 3) // 62.83185307179586surfaceAreaPyramidSquare
// Takes numbers and returns surface area pyramid square.
easyJS.surfaceAreaPyramidSquare(2, 3) // 16surfaceAreaRectPrism
// Takes numbers and returns surface area rect prism.
easyJS.surfaceAreaRectPrism(2, 3) // nullsurfaceAreaSphere
// Takes numbers and returns surface area sphere.
easyJS.surfaceAreaSphere(2, 3) // 50.26548245743669tanDeg
// Takes numbers and returns tan deg.
easyJS.tanDeg(2, 3) // 0.03492076949174773toFloat
// Takes numbers and returns to float.
easyJS.toFloat(2, 3) // 2toInt
// Takes numbers and returns to int.
easyJS.toInt(2, 3) // 2toNumber
// Takes numbers and returns to number.
easyJS.toNumber(2, 3) // 2triangleWave
// Takes numbers and returns triangle wave.
easyJS.triangleWave(2, 3) // -0.3333333333333335triangularNumber
// Takes numbers and returns triangular number.
easyJS.triangularNumber(2, 3) // 3turnToDeg
// Takes numbers and returns turn to deg.
easyJS.turnToDeg(2, 3) // 720turnToRad
// Takes numbers and returns turn to rad.
easyJS.turnToRad(2, 3) // 12.566370614359172variance
// Takes numbers and returns variance.
easyJS.variance(2, 3) // 0.25varianceSample
// Takes numbers and returns variance sample.
easyJS.varianceSample(2, 3) // 0.5volumeCone
// Takes numbers and returns volume cone.
easyJS.volumeCone(2, 3) // 12.566370614359172volumeCube
// Takes numbers and returns volume cube.
easyJS.volumeCube(2, 3) // 8volumeCylinder
// Takes numbers and returns volume cylinder.
easyJS.volumeCylinder(2, 3) // 37.69911184307752volumePyramidSquare
// Takes numbers and returns volume pyramid square.
easyJS.volumePyramidSquare(2, 3) // 2volumeRectPrism
// Takes numbers and returns volume rect prism.
easyJS.volumeRectPrism(2, 3) // nullvolumeSphere
// Takes numbers and returns volume sphere.
easyJS.volumeSphere(2, 3) // 33.510321638291124wrap
// Takes numbers and returns wrap.
easyJS.wrap(2, 3) // nullwrapAngle
// Takes numbers and returns wrap angle.
easyJS.wrapAngle(2, 3) // 2wrapPi
// Takes numbers and returns wrap pi.
easyJS.wrapPi(2, 3) // 2Array
arrayGroupBy
// Takes an array and returns array group by.
easyJS.arrayGroupBy([1,2,3]) // {"undefined":[1,2,3]}asArray
// Takes an array and returns as array.
easyJS.asArray([1,2,3]) // [1,2,3]avgBy
// Takes an array and returns avg by.
easyJS.avgBy([{"v":1},{"v":3}], fn) // 2chunk
// Takes an array and returns chunk.
easyJS.chunk([1,2,3]) // [[]]chunkBy
// Takes an array and returns chunk by.
easyJS.chunkBy([1,1,2,2,3], fn) // [[1,1],[2,2],[3]]chunkWhile
// Takes an array and returns chunk while.
easyJS.chunkWhile([1,2,3,4], fn) // [[1,2],[3,4]]compact
// Takes an array and returns compact.
easyJS.compact([1,2,3]) // [1,2,3]compactBy
// Takes an array and returns compact by.
easyJS.compactBy([0,1,2], fn) // [1,2]count
// Takes an array and returns count.
easyJS.count([1,2,3]) // 3countBy
// Takes an array and returns count by.
easyJS.countBy([1,2,3,4], fn) // {"0":2,"1":2}difference
// Takes an array and returns difference.
easyJS.difference([1,2,3]) // [1,2,3]differenceBy
// Takes an array and returns difference by.
easyJS.differenceBy([1,2,3], [2], fn) // [1,3]drop
// Takes an array and returns drop.
easyJS.drop([1,2,3]) // [1,2,3]dropRight
// Takes an array and returns drop right.
easyJS.dropRight([1,2,3]) // []dropUntil
// Takes an array and returns drop until.
easyJS.dropUntil([1,2,3,4], fn) // [3,4]dropWhile
// Takes an array and returns drop while.
easyJS.dropWhile([1,2,3,4], fn) // [3,4]findLast
// Takes an array and returns find last.
easyJS.findLast([1,2,3,4], fn) // 4findLastIndex
// Takes an array and returns find last index.
easyJS.findLastIndex([1,2,3,4], fn) // 3first
// Takes an array and returns first.
easyJS.first([1,2,3]) // 1flatten
// Takes an array and returns flatten.
easyJS.flatten([1,2,3]) // [1,2,3]flattenDeep
// Takes an array and returns flatten deep.
easyJS.flattenDeep([1,2,3]) // [1,2,3]flattenDepth
// Takes an array and returns flatten depth.
easyJS.flattenDepth([1,2,3]) // [1,2,3]fromSet
// Takes an array and returns from set.
easyJS.fromSet([1,2,3]) // [1,2,3]groupBy
// Takes an array and returns group by.
easyJS.groupBy([1,2,3,4], fn) // {"0":[2,4],"1":[1,3]}head
// Takes an array and returns head.
easyJS.head([1,2,3]) // 1inArray
// Takes an array and returns in array.
easyJS.inArray([1,2,3]) // falseindexBy
// Takes an array and returns index by.
easyJS.indexBy([{"id":1},{"id":2}], fn) // {"1":{"id":1},"2":{"id":2}}indexOfAll
// Takes an array and returns index of all.
easyJS.indexOfAll([1,2,3]) // []init
// Takes an array and returns init.
easyJS.init([1,2,3]) // [1,2]insertAt
// Takes an array and returns insert at.
easyJS.insertAt([1,2,3]) // [null,1,2,3]intersection
// Takes an array and returns intersection.
easyJS.intersection([1,2,3]) // [1,2,3]intersectionBy
// Takes an array and returns intersection by.
easyJS.intersectionBy([1,2,3], [2,4], fn) // [2]isArray
// Checks if is array is true.
easyJS.isArray([1,2,3]) // truekeyBy
// Takes an array and returns key by.
easyJS.keyBy([{"id":1},{"id":2}], fn) // {"1":{"id":1},"2":{"id":2}}last
// Takes an array and returns last.
easyJS.last([1,2,3]) // 3lastIndex
// Takes an array and returns last index.
easyJS.lastIndex([1,2,3]) // 2lastIndexOf
// Takes an array and returns last index of.
easyJS.lastIndexOf([1,2,3]) // -1move
// Takes an array and returns move.
easyJS.move([1,2,3]) // [1,2,3]partition
// Takes an array and returns partition.
easyJS.partition([1,2,3,4], fn) // [[2,4],[1,3]]pluck
// Takes an array and returns pluck.
easyJS.pluck([{"a":1},{"a":2}], "a") // [1,2]range
// Takes an array and returns range.
easyJS.range([1,2,3]) // []removeAt
// Takes an array and returns remove at.
easyJS.removeAt([1,2,3]) // [2,3]repeatArray
// Takes an array and returns repeat array.
easyJS.repeatArray([1,2,3]) // []rotate
// Takes an array and returns rotate.
easyJS.rotate([1,2,3]) // [1,2,3]rotateLeft
// Takes an array and returns rotate left.
easyJS.rotateLeft([1,2,3]) // [1,2,3]rotateRight
// Takes an array and returns rotate right.
easyJS.rotateRight([1,2,3]) // [1,2,3]sample
// Takes an array and returns sample.
easyJS.sample([1,2,3]) // random (example: 2)shuffle
// Takes an array and returns shuffle.
easyJS.shuffle([1,2,3]) // random (example: [2,1,3])slidingWindow
// Takes an array and returns sliding window.
easyJS.slidingWindow([1,2,3]) // []sortBy
// Takes an array and returns sort by.
easyJS.sortBy([{"n":2},{"n":1}], fn) // [{"n":1},{"n":2}]sumBy
// Takes an array and returns sum by.
easyJS.sumBy([{"v":1},{"v":2}], fn) // 3swap
// Takes an array and returns swap.
easyJS.swap([1,2,3]) // [1,2,3]tail
// Takes an array and returns tail.
easyJS.tail([1,2,3]) // [2,3]take
// Takes an array and returns take.
easyJS.take([1,2,3]) // [1,2,3]takeRight
// Takes an array and returns take right.
easyJS.takeRight([1,2,3]) // [1,2,3]takeUntil
// Takes an array and returns take until.
easyJS.takeUntil([1,2,3,4], fn) // [1,2]takeWhile
// Takes an array and returns take while.
easyJS.takeWhile([1,2,3,4], fn) // [1,2]toSet
// Takes an array and returns to set.
easyJS.toSet([1,2,3]) // {}union
// Takes an array and returns union.
easyJS.union([1,2,3]) // [1,2,3]unionBy
// Takes an array and returns union by.
easyJS.unionBy([{"id":1},{"id":2}], [{"id":2},{"id":3}], fn) // [{"id":1},{"id":2},{"id":3}]uniq
// Takes an array and returns uniq.
easyJS.uniq([1,2,3]) // [1,2,3]uniqueBy
// Takes an array and returns unique by.
easyJS.uniqueBy([1,2,3]) // [1]uniqueSorted
// Takes an array and returns unique sorted.
easyJS.uniqueSorted([1,2,3]) // [1,2,3]unzip
// Takes an array and returns unzip.
easyJS.unzip([1,2,3]) // []zip
// Takes an array and returns zip.
easyJS.zip([1,2,3]) // [[1],[2],[3]]zipObject
// Takes an array and returns zip object.
easyJS.zipObject([1,2,3]) // {}String
camelCase
// Takes a string and returns camel case.
easyJS.camelCase("hello world") // "helloWorld"capitalize
// Takes a string and returns capitalize.
easyJS.capitalize("hello world") // "Hello world"collapseWhitespace
// Takes a string and returns collapse whitespace.
easyJS.collapseWhitespace("hello world") // "hello world"containsAny
// Takes a string and returns contains any.
easyJS.containsAny("hello world", ["ell","zzz"]) // truecountChars
// Takes a string and returns count chars.
easyJS.countChars("hello world") // 11countOccurrences
// Takes a string and returns count occurrences.
easyJS.countOccurrences("a-b-a", "a") // 2countWords
// Takes a string and returns count words.
easyJS.countWords("hello world") // 2endsWith
// Takes a string and returns ends with.
easyJS.endsWith("hello world", "ld") // trueendsWithAny
// Takes a string and returns ends with any.
easyJS.endsWithAny("hello world", ["ld","zz"]) // trueensurePrefix
// Takes a string and returns ensure prefix.
easyJS.ensurePrefix("world", "hello ") // "hello world"ensureSuffix
// Takes a string and returns ensure suffix.
easyJS.ensureSuffix("hello", "!") // "hello!"includes
// Takes a string and returns includes.
easyJS.includes("hello world", "lo") // trueisBlank
// Checks if is blank is true.
easyJS.isBlank("hello world") // falseisLower
// Checks if is lower is true.
easyJS.isLower("hello world") // trueisUpper
// Checks if is upper is true.
easyJS.isUpper("hello world") // falsekebabCase
// Takes a string and returns kebab case.
easyJS.kebabCase("hello world") // "hello-world"lines
// Takes a string and returns lines.
easyJS.lines("hello world") // ["hello world"]mask
// Takes a string and returns mask.
easyJS.mask("123456", 2, "*") // "****56"normalizeString
// Takes a string and returns normalize string.
easyJS.normalizeString("hello world") // "hello world"padCenter
// Takes a string and returns pad center.
easyJS.padCenter("hi", 6, "-") // "--hi--"padLeft
// Takes a string and returns pad left.
easyJS.padLeft("7", 3, "0") // "007"padRight
// Takes a string and returns pad right.
easyJS.padRight("7", 3, "0") // "700"pascalCase
// Takes a string and returns pascal case.
easyJS.pascalCase("hello world") // "HelloWorld"removeConsonants
// Takes a string and returns remove consonants.
easyJS.removeConsonants("hello world") // "eowod"removeVowels
// Takes a string and returns remove vowels.
easyJS.removeVowels("hello world") // "hll wrld"repeat
// Takes a string and returns repeat.
easyJS.repeat("hello world") // ""replaceAll
// Takes a string and returns replace all.
easyJS.replaceAll("hello world") // "hello world"replaceFirst
// Takes a string and returns replace first.
easyJS.replaceFirst("a-b-a", "a", "x") // "x-b-a"replaceLast
// Takes a string and returns replace last.
easyJS.replaceLast("a-b-a", "a", "x") // "a-b-x"reverseString
// Takes a string and returns reverse string.
easyJS.reverseString("hello world") // "dlrow olleh"slugify
// Takes a string and returns slugify.
easyJS.slugify("hello world") // "hello-world"snakeCase
// Takes a string and returns snake case.
easyJS.snakeCase("hello world") // "hello_world"startsWith
// Takes a string and returns starts with.
easyJS.startsWith("hello world", "he") // truestartsWithAny
// Takes a string and returns starts with any.
easyJS.startsWithAny("hello world", ["he","yo"]) // truestripNonAlpha
// Takes a string and returns strip non alpha.
easyJS.stripNonAlpha("hello world") // "helloworld"stripPrefix
// Takes a string and returns strip prefix.
easyJS.stripPrefix("hello", "he") // "llo"stripSuffix
// Takes a string and returns strip suffix.
easyJS.stripSuffix("hello", "lo") // "hel"surround
// Takes a string and returns surround.
easyJS.surround("hi", "<", ">") // "<hi>"swapCase
// Takes a string and returns swap case.
easyJS.swapCase("hello world") // "HELLO WORLD"toLower
// Takes a string and returns to lower.
easyJS.toLower("hello world") // "hello world"toTitleCase
// Takes a string and returns to title case.
easyJS.toTitleCase("hello world") // "Hello World"toTitleCaseWords
// Takes a string and returns to title case words.
easyJS.toTitleCaseWords("hello world") // "Hello World"toUpper
// Takes a string and returns to upper.
easyJS.toUpper("hello world") // "HELLO WORLD"trim
// Takes a string and returns trim.
easyJS.trim("hello world") // "hello world"trimEnd
// Takes a string and returns trim end.
easyJS.trimEnd("hello world") // "hello world"trimStart
// Takes a string and returns trim start.
easyJS.trimStart("hello world") // "hello world"truncate
// Takes a string and returns truncate.
easyJS.truncate("hello world") // "..."unmask
// Takes a string and returns unmask.
easyJS.unmask("**1234", "*") // "1234"words
// Takes a string and returns words.
easyJS.words("hello world") // ["hello","world"]Object
cloneShallow
// Takes an object and returns clone shallow.
easyJS.cloneShallow({"a":1,"b":2}) // {"a":1,"b":2}deepMerge
// Takes an object and returns deep merge.
easyJS.deepMerge({"a":{"b":1}}, {"a":{"c":2}}) // {"a":{"b":1,"c":2}}defaults
// Takes an object and returns defaults.
easyJS.defaults({"a":1}, {"a":2,"b":2}) // {"a":1,"b":2}defaultsDeep
// Takes an object and returns defaults deep.
easyJS.defaultsDeep({"a":{"b":1}}, {"a":{"c":2}}) // {"a":{"b":1,"c":2}}entries
// Takes an object and returns entries.
easyJS.entries({"a":1,"b":2}) // [["a",1],["b",2]]filterKeys
// Takes an object and returns filter keys.
easyJS.filterKeys({"a":1,"b":2}, fn) // {"a":1}filterValues
// Takes an object and returns filter values.
easyJS.filterValues({"a":1,"b":2}, fn) // {"b":2}fromEntries
// Takes an object and returns from entries.
easyJS.fromEntries({"a":1,"b":2}) // {}fromPairs
// Takes an object and returns from pairs.
easyJS.fromPairs([["a",1],["b",2]]) // {"a":1,"b":2}has
// Takes an object and returns has.
easyJS.has({"a":1,"b":2}) // falsehasPath
// Takes an object and returns has path.
easyJS.hasPath({"a":{"b":2}}, "a.b") // trueinvert
// Takes an object and returns invert.
easyJS.invert({"a":1,"b":2}) // {"1":"a","2":"b"}invertBy
// Takes an object and returns invert by.
easyJS.invertBy({"a":1,"b":2}, fn) // {"1":"a","2":"b"}isEmptyObject
// Checks if is empty object is true.
easyJS.isEmptyObject({"a":1,"b":2}) // falseisObject
// Checks if is object is true.
easyJS.isObject({"a":1,"b":2}) // truekeys
// Takes an object and returns keys.
easyJS.keys({"a":1,"b":2}) // ["a","b"]mapEntries
// Takes an object and returns map entries.
easyJS.mapEntries({"a":1}, fn) // [["a",2]]mapKeys
// Takes an object and returns map keys.
easyJS.mapKeys({"a":1,"b":2}, fn) // {"A":1,"B":2}mapValues
// Takes an object and returns map values.
easyJS.mapValues({"a":1,"b":2}, fn) // {"a":2,"b":4}merge
// Takes an object and returns merge.
easyJS.merge({"a":1,"b":2}) // {"a":1,"b":2}mergeWith
// Takes an object and returns merge with.
easyJS.mergeWith({"a":1}, {"a":2}, fn) // {"a":1}objectCompact
// Takes an object and returns object compact.
easyJS.objectCompact({"a":1,"b":2}) // {"a":1,"b":2}omit
// Takes an object and returns omit.
easyJS.omit({"a":1,"b":2}) // {"a":1,"b":2}omitBy
// Takes an object and returns omit by.
easyJS.omitBy({"a":1,"b":2}, fn) // {"a":1}omitPath
// Takes an object and returns omit path.
easyJS.omitPath({"a":{"b":2},"c":3}, ["a.b"]) // {"a":{},"c":3}pick
// Takes an object and returns pick.
easyJS.pick({"a":1,"b":2}) // {}pickBy
// Takes an object and returns pick by.
easyJS.pickBy({"a":1,"b":2}, fn) // {"b":2}pickPath
// Takes an object and returns pick path.
easyJS.pickPath({"a":{"b":2},"c":3}, ["a.b","c"]) // {"a":{"b":2},"c":3}safeGet
// Takes an object and returns safe get.
easyJS.safeGet({"a":{"b":2}}, "a.b", 0) // 2safeSet
// Takes an object and returns safe set.
easyJS.safeSet({"a":{"b":3}}, "a.b", 3) // {"a":{"b":3}}size
// Takes an object and returns size.
easyJS.size({"a":1,"b":2}) // 2toPairs
// Takes an object and returns to pairs.
easyJS.toPairs({"a":1,"b":2}) // [["a",1],["b",2]]unsetPath
// Takes an object and returns unset path.
easyJS.unsetPath({"a":{}}, "a.b") // truevalues
// Takes an object and returns values.
easyJS.values({"a":1,"b":2}) // [1,2]zipObjectDeep
// Takes an object and returns zip object deep.
easyJS.zipObjectDeep(["a.b","c"], [1,2]) // {"a":{"b":1},"c":2}Util
anyOf
// any Of.
easyJS.anyOf("tom", ["thomas","tommy","tom"]) // truearrayFromArgs
// array From Args.
easyJS.arrayFromArgs([1,2,3]) // [1,2,3]chain
// chain.
easyJS.chain([1,2,2,3]).uniq().take(2).value() // [1,2]compose
// compose.
easyJS.compose(fn, fn) // undefineddebounce
// debounce.
easyJS.debounce(fn, 10) // undefineddeepClone
// deep Clone.
easyJS.deepClone({a:1, b:{c:2}}) // {a:1,b:{c:2}}defaultTo
// default To.
easyJS.defaultTo(null, 5) // 5defer
// defer.
easyJS.defer() // {}eqAny
// eq Any.
easyJS.eqAny(2, [1,2,3]) // trueidentity
// identity.
easyJS.identity("hi") // "hi"install
// install.
easyJS.install() // adds prototype helpersisEmpty
// Checks if is empty is true.
easyJS.isEmpty([]) // trueisNil
// Checks if is nil is true.
easyJS.isNil(undefined) // truememoize
// memoize.
easyJS.memoize(fn) // undefinednoop
// noop.
easyJS.noop() // undefinednoopAsync
// noop Async.
easyJS.noopAsync() // {}once
// once.
easyJS.once(fn) // undefinedonceAsync
// once Async.
easyJS.onceAsync(async n => n + 1)(1) // Promise (example: 2)parsePath
// parse Path.
easyJS.parsePath("a.b") // ["a","b"]pipe
// pipe.
easyJS.pipe(fn, fn) // undefinedsafeJsonParse
// safe Json Parse.
easyJS.safeJsonParse("{\"a\":1}", {}) // {"a":1}safeJsonStringify
// safe Json Stringify.
easyJS.safeJsonStringify({"a":1}) // "{\"a\":1}"sleep
// sleep.
easyJS.sleep(100) // Promise (resolves after ~100ms)tap
// tap.
easyJS.tap(5, fn) // 5throttle
// throttle.
easyJS.throttle(fn, 10) // undefinedtimes
// times.
easyJS.times(3, fn) // [0,1,2]tryCatch
// try Catch.
easyJS.tryCatch(fn, fn) // "fallback"Prototype Helpers (Only After easyJS.install())
These methods are added to built-in prototypes and only work after running easyJS.install().
Array
.shuffle()
easyJS.install()
[1, 2, 3].shuffle() // random order.unique()
easyJS.install()
[1, 2, 2].unique() // [1, 2].chunk(size)
easyJS.install()
[1, 2, 3, 4].chunk(2) // [[1, 2], [3, 4]].move(from, to)
easyJS.install()
[1, 2, 3].move(0, 2) // [2, 3, 1].groupBy(fn)
easyJS.install()
[1, 2, 3, 4].groupBy(x => x % 2) // { 0: [2, 4], 1: [1, 3] }.compact(fn?)
easyJS.install()
[0, null, 2].compact() // [0, 2].flatten()
easyJS.install()
[1, [2, 3]].flatten() // [1, 2, 3].first()
easyJS.install()
[9, 8, 7].first() // 9.last()
easyJS.install()
[9, 8, 7].last() // 7.take(n)
easyJS.install()
[1, 2, 3].take(2) // [1, 2].takeRight(n)
easyJS.install()
[1, 2, 3].takeRight(2) // [2, 3].drop(n)
easyJS.install()
[1, 2, 3].drop(1) // [2, 3].dropRight(n)
easyJS.install()
[1, 2, 3].dropRight(1) // [1, 2]Object
.mapKeys(fn)
easyJS.install()
({ a: 1, b: 2 }).mapKeys(k => k.toUpperCase()) // { A: 1, B: 2 }.pick(keys)
easyJS.install()
({ a: 1, b: 2 }).pick(["a"]) // { a: 1 }.invert()
easyJS.install()
({ a: 1 }).invert() // { "1": "a" }.compact()
easyJS.install()
({ a: null, b: 2 }).compact() // { b: 2 }.omit(keys)
easyJS.install()
({ a: 1, b: 2 }).omit(["b"]) // { a: 1 }.has(key)
easyJS.install()
({ a: 1 }).has("a") // true.merge(...objs)
easyJS.install()
({ a: 1 }).merge({ b: 2 }) // { a: 1, b: 2 }.deepMerge(...objs)
easyJS.install()
({ a: { b: 1 } }).deepMerge({ a: { c: 2 } }) // { a: { b: 1, c: 2 } }.size()
easyJS.install()
({ a: 1, b: 2 }).size() // 2String
.toTitleCase()
easyJS.install()
"hello world".toTitleCase() // "Hello World".truncate(len)
easyJS.install()
"hello world".truncate(8) // "hello...".replaceAllEasy(sub, rep)
easyJS.install()
"a-b".replaceAllEasy("-", "_") // "a_b".countWords()
easyJS.install()
"hi there".countWords() // 2.slugify()
easyJS.install()
"Hello World!".slugify() // "hello-world".padLeft(len, ch?)
easyJS.install()
"7".padLeft(3, "0") // "007".padRight(len, ch?)
easyJS.install()
"7".padRight(3, "0") // "700".repeatEasy(n)
easyJS.install()
"ha".repeatEasy(3) // "hahaha".stripNonAlpha()
easyJS.install()
"a-b_c".stripNonAlpha() // "abc".isBlank()
easyJS.install()
" ".isBlank() // true.normalizeString()
easyJS.install()
" ToM ".normalizeString() // "tom"