1.0.3 • Published 10 months ago

min-max-utk v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

min-max-utk

min-max-utk is a lightweight JavaScript utility library that provides functions to find the minimum and maximum values from multiple numbers, strings, or booleans. It also includes a basic test function to verify that the library is working correctly.

Features

  • test(): Confirms the library is working.
  • findMin(): Returns the minimum value from numbers, strings, or booleans.
  • findMax(): Returns the maximum value from numbers, strings, or booleans.

Installation

You can install this library via npm:

npm install min-max-utk

Or using Yarn:

yarn add min-max-utk

Usage

After installing the library, you can import the functions and start using them in your JavaScript project.

Importing the Functions

const { test, findMin, findMax } = require('min-max-utk');

test Function

The test() function is used to verify that the library is functioning correctly. It returns a simple string confirming that the library is working.

Example:

console.log(test());

Output:

Library is working!

findMin Function

The findMin() function accepts values of the same type (either numbers, strings, or booleans) and returns the smallest value. If you provide values of different types, the function will throw an error.

Syntax:

findMin(value1, value2, value3);

Parameters:

  • values: A series of arguments that are either all numbers, all strings, or all booleans.

Example 1: Finding the Minimum of Numbers

console.log(findMin(5, 2, 9, 3)); 

Output:

2

Example 2: Finding the Minimum of Strings (Lexicographically)

console.log(findMin('apple', 'banana', 'grape')); 

Output:

apple

Example 3: Finding the Minimum of Booleans

console.log(findMin(true, false, true)); 

Output:

false

Error Case: Mixed Types

If you pass values of different types, the function will throw an error.

console.log(findMin(5, 'banana', true)); 

Output:

Error: All arguments must be of the same type.

findMax Function

The findMax() function is similar to findMin(), but it returns the largest value from the array of arguments. Like findMin(), it works for numbers, strings (lexicographically), and booleans.

Syntax:

findMax(value1, value2, value3);

Parameters:

  • values: A series of arguments that are either all numbers, all strings, or all booleans.

Example 1: Finding the Maximum of Numbers

console.log(findMax(5, 2, 9, 3)); 

Output:

9

Example 2: Finding the Maximum of Strings (Lexicographically)

console.log(findMax('apple', 'banana', 'grape')); 

Output:

grape

Example 3: Finding the Maximum of Booleans

console.log(findMax(true, false, true)); 

Output:

true

Error Case: Mixed Types

If you pass mixed types, the function will throw an error.

console.log(findMax(5, 'banana', true)); 

Output:

Error: All arguments must be of the same type.

Error Handling

Errors in findMin() and findMax():

  1. No arguments provided:
    If you call the functions without passing any arguments, they will throw an error:

    Error: No arguments provided.
  2. Mixed types in arguments:
    Both functions accept arguments of only one type at a time. If a combination of types is passed, the function will throw an error:

    Error: All arguments must be of the same type.
  3. Unsupported types:
    The library supports only number, string, and boolean. If you pass any other type, the functions will throw an error:

    Error: Unsupported type.

Example Project

Here’s an example of how to use min-max-utk in your project:

const { test, findMin, findMax } = require('min-max-utk');

// Test the library
console.log(test());  // Output: Library is working!

// Find minimum value from a list of numbers
console.log(findMin(10, 20, 5, 8));  // Output: 5

// Find maximum value from a list of strings
console.log(findMax('zebra', 'lion', 'tiger'));  // Output: zebra

// Find minimum value from a list of booleans
console.log(findMin(true, false, true));  // Output: false

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contributing

Contributions are welcome! If you'd like to contribute to this project, please fork the repository, create a new branch, and submit a pull request.


Author

Developed by Utkarsh Gupta.


Version History

  • v1.0.0: Initial release with test, findMin, and findMax functions.

Keywords

  • min
  • max
  • utility
  • JavaScript
  • minimum
  • maximum
  • numbers
  • strings
  • booleans

This README.md file is optimized for publishing on npm, clearly explaining how to install, use, and integrate the library in JavaScript projects, along with examples, error handling, and version history.

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago