1.1.1 • Published 1 year ago

vic-library v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

vic. v 1.1.1

Hey, so I made a light-weight library with functions that come in handy from time to time. Overtime, this will grow. There's some Leetcode questions in here too that I like to compile together in one place to study/refer to later on. Also contains some functions found in the Lodash library. Just helps to streamline workflow so you don't have to write functions you've used before over and over.

Update: Added some math functions

Install it using npm i vic-library

Functions:

(If you ctrl+f and find a few useful functions you might need, this library is great for you because it's not massive like the Lodash library, for example.)

vic.clamp(number, lower, upper)

Takes 3 arguments:

  • Integer
  • Lower bound (Int)
  • Upper bound (Int) Returns:
  • Integer If the integer provided is smaller than the lower bound, the function returns the lower bound as the final number.

vic.inRange(number, start, end)

Takes 3 arguments:

  • Integer
  • Start value (Int)
  • End value (Int) Returns:
  • Boolean Checks the provided integer is withing range of start value and end value. If outside of provided range, the function returns a value of false. NOTE If no end value is proved, start value becomes 0 and provided start value becomes end value. If the start value is larger than the end value, the function will swap the values. This functionality is provided as a fail-safe should the user pass in incorrect arguments.

vic.words(string)

Takes 1 argument:

  • String Returns:
  • Array Splits long strings into an array of each word found in the original string.

vic.pad(string, length)

Takes 2 arguments:

  • String
  • Length (Int) Returns:
  • String Adds padding (spaces) to each side of the array to meet the desired length provided.

vic.translateToWhaleTalk(string)

Takes 1 argument:

  • String Returns
  • String Translate given string into a whale-intelligable language. e and u found inside the string will be double. Filters out consonants. Returned string will be in all capitals.

vic.has(object, key)

Takes 2 arguments:

  • Object
  • Key Returns:
  • Boolean Returns true if provided object contains the key and the key contains a value. Returns false if the provided object does not contain the provided key or the key does not have a value. NOTE Currently doesn't work with nested values

vic.invert(object)

Takes 1 argument:

  • Object Returns:
  • Object Iterates through each key of the provided object and swaps the key and value. NOTE In the case of duplicate values in the object, subsequent values will overwrite property assignments of previous values.

vic.findKey(object, predicate)

Takes 2 arguments:

  • Object
  • A predicate function (return Boolean) Returns:
  • Object.key Iterates through each key / value pair and calls the provided predicate function to test the value at its corresponding key. Returns the first key with a truthy value. Returns undefined if no key is truthy.

vic.drop(array, number)

Takes 2 arguments:

  • Array
  • Integer Returns
  • Array Removes a value from an array at a given value.

vic.dropWhile(array, predicate)

Takes 2 arguments:

  • Object
  • A predicate function (takes 3 args: current index, current element index, and the provided array) Returns
  • Array Creates a new copy of the provided array, dropping elements from the beginning of the array until an element causes the predicate function to return a falsy value.

vic.chunk(array, size)

Takes 2 arguments:

  • Array
  • Size (Int) Returns:
  • Array Disjunction the provided array into an array of arrays at the provided size. NOTE If the array cannot be broken up evenly, the last array chunk will be truncated to math the provided size argument. NOTE If no size is supplied, it's value will be set to 1.

vic.romanToInt(string)

Takes 1 argument:

  • String Returns:
  • Integer Converts a given roman numeral as a string and returns the corresponding integer. The European Spanish language uses a lot of roman numerals so this is useful in translation scenarios.

vic.priceFormat(number)

Takes 1 argument:

  • Integer Returns:
  • String Formats a given integer into a string with the appropriate decimals, commas, and dollar sign. Currently configured to USD.

vic.solveQuadratic(a, b, c)

Takes 3 arguments:

  • Integer (A value of quadratic)
  • Integer (B value of quadratic)
  • Integer (C value of quadratic) Returns:
  • String || Array Finds x intercepts of parabola from quadratic equation (a^2x + bx + c) in an array. If no x intercepts are found, returns string format of imaginary solutions (i).

vic.factorial(number)

Takes1 argument:

  • Integer Returns:
  • Integer Finds factorial of any number Example: 5! = 5 4 3 2 1 = 120.
1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago