Giter Site home page Giter Site logo

Handy Script Cover

Handy Script

A set of useful javascript modules that makes the javascript development context easier

NPM DOWNLOADS NPM LICENSE NPM VERSION

JEST CI TEST Socket Badge

Installation

You can install Handy Script using npm:

npm install handyscript

Alternatively, you can use the CDN script to include the hs.min.js in your HTML file

<script src="https://unpkg.com/browse/[email protected]/dist/hs.min.js"></script>

Alternatively, you can use the CDN script to include the hs.min.js in your HTML file

<!-- VIA: jsdelivr CDN -->
<script src="https://cdn.jsdelivr.net/npm/handyscript@latest/dist/hs.min.js"></script>
<!-- VIA: unpkg CDN -->
<script src="https://unpkg.com/handyscript@latest/dist/hs.min.js"></script>

Otherwise, you can download the hs.min.js file from the dist directory and include it in your HTML file, or click here to download it directly

<script src="path/to/hs.min.js"></script>

Usage

Once you have installed or included the hs.min.js file, you can start using the functions in your code.

// Import the handyscript to extend the prebuilt js modules
import "handyscript";
// explicitly use the HOperators, HashMap
import { HashMap } from "handyscript"

// Array manipulation:
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log(arr.chunk(3)); // [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
console.log(arr.shuffle()); // [3, 2, 5, 1, 4, 6, 7, 8, 10, 9]
console.log(arr.shuffle().bubbleSort()); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

// The Math Module:
console.log(Math.randomInt(1, 10)); // 7

// HashMap
const obj = {
    name: "John",
    age: 20,
    weight: 70,
    height: 180,
    isMarried: true,
    isStudent: true,
};

const map = new HashMap(obj);

console.log(map.getKeysByValue(true)); // ["isMarried","isStudent"]

// Operators:
 const obj = { name:"ahmed", age: 20 };
 HOperators.objloop(obj, (key, val) => console.log(key, val))
 // name ahmed
 // age 20

Functionalities

check our detailed wiki documentation here

Shuffles the elements of the array array and returns a new array.

Array.prototype.shuffle()

The binarySearch method searches an array for the specified item using the binary search algorithm. you can specify the sort algorithm to be used in sorting the array before searching

Array.prototype.binarySearch(item, sortalgo)

Sorting the array using specific sort algorithms like : bubbleSort

Array.prototype.bubbleSort()
  • bubbleSort
  • insertionSort
  • selectionSort
  • mergeSort
  • quickSort
  • heapSort
  • countingSort # ⚠ Only works with arrays of numbers
  • shellSort
  • bucketSor
  • radixSort # ⚠ Only works with arrays of numbers

There is more to discover here

Matrix

import { Matrix } from "handyscript";

// Example usage
const matrix1 = new Matrix([
  [1, 2, 3],
  [4, 5, 6],
]);
const matrix2 = new Matrix([
  [1, 2],
  [3, 4],
  [5, 6],
]);

const matrixAdd = Matrix.add(matrix1, matrix2);
console.log("Matrix 1 + Matrix 2:");
matrixAdd.log();

const matrixMulti = Matrix.multiply(matrix1, matrix2);
console.log("Matrix 1 * Matrix 2:");
matrixMulti.log();

There is more to discover ✨

Math

// import the hole package:
import "handyscript";
// or import the target lib/module
import "handyscript/lib/math";

Math.clamp(value, min = 1, max)
console.log(Math.randomInt(1, 10)); // 7

Returns a value that is clamped between min and max.

There is more to discover ✨

String

// import the hole package:
import "handyscript";
// or import the target lib/module
import "handyscript/lib/string";

String.prototype.toCapitalCase(); // "Hello World" // capitalizes the first letter of every word in a string.
String.prototype.toCamelCase();// "helloWorld": // capitalizes the first letter of every word starting with the second word in a string and removes all the spaces.
String.prototype.reverse(); // reverse a string and string
String.prototype.indexesOf(target, startPosition? = 0); // Returns the positions of the all occurrence of a substring.
String.prototype.escape(isForAttribute? = false): string; // escape a string from all white spaces and all control characters (characters with a code point < U+0020).

Extends the builtin String module for more string manipulation

There is more to discover ✨

Number

// import the hole package:
import "handyscript";
// or import the target lib/module
import "handyscript/lib/number";

Number.prototype.toHuman() // Returns a string representation of a number in human readable format. like 1K, 1M, 1B, 1T, etc.
Number.prototype.toReadable(separator? = "-") // Returns a string representation of a number readable format. like 10-000, 1-000-000, 1-000-000-000, etc.

Extends the prebuilt Number module for more number manipulation

There is more to discover ✨

var data = {
    name: 'John Doe',
    age: 30,
    email: '[email protected]',
    address: {
        city: 'New York',
        street: '123 Main St'
    }
};

const schema = {
    name: { type: String, required: true },
    age: { type: Number },
    email: { type: String, required: true },
    address: {
        type: Object,
        properties: {
            city: { type: String },
            street: { type: String }
        }
    }
};

JSON.validateSchema(data, schema); // True

There is more to discover Here

Handy Script's Projects

handy icon handy

a javascript library for dummies

handyscript icon handyscript

A set of useful javascript modules that extends the javascript core context.

handyutility icon handyutility

a set of Javascript supplements utilities and functions

weboc icon weboc

The official handyscript package web documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.