Skip to content

Instantly share code, notes, and snippets.

View bhaireshm's full-sized avatar
🐕

Bhairesh M bhaireshm

🐕
View GitHub Profile
@bhaireshm
bhaireshm / uniqueArrayOfObjects.js
Created August 8, 2022 15:11
Compares all the objects(both key and value) in the given array and returns the unique array of objects.
/**
* Compares all the objects(both key and value) in the given array and returns the unique array.
*
* @param {Object[]} arr - An array of objects.
* @returns unique array of object(s).
*
* @example uniqueArrayOfObjects([{a: 2}, {a: 2}]); // [{"a": 2}]
* @example uniqueArrayOfObjects([{a: {b: 2}}, {a: {b: 2}}]); // [{"a": {"b": 2}}]
* @example uniqueArrayOfObjects([{a: 2}, {a: 2, b: 3}]); // [{a: 2}, {a: 2, b: 3}]
*/
@bhaireshm
bhaireshm / currencyFormatter.js
Created August 26, 2022 14:04
Converts number into formatted currency value.
/**
* Converts number into formatted currency value.
*
* @param {Number} val - Integer value
* @param {Intl.NumberFormatOptions} options - An object with some or all of the properties of Intl.NumberFormatOptions
* @returns formatted value.
*
* @example
* console.log(currencyFormatter(1234567890.1997)); // ₹1,23,45,67,890.20
* console.log(currencyFormatter(1234567890, {locales: "en-US", currency: "USD", maximumFractionDigits: 0})); // $1,234,567,890
@bhaireshm
bhaireshm / dataFormatter.js
Created April 19, 2023 17:17
Data formatter - rename/customise keyname and values as you require, even nested keys and nested values can be defined.
/**
* Data formatter - rename/customise keyname and values as you require, even nested keys and nested values can be defined.
*
* @param {object} obj - data to be formateted
* @param {string} formatter - key:valuePath, each key value is separated by comma
* @example "alterName:key" or "alterName:nested.key" or "nested.alterName:key" or "nested.alterName:nested.key"
* @param {object} options
* @param {object} options.error - default true, returns error content if any key or value is not found
* @param {object} options.oldData - default true, returns object
* @returns return modified object along with the provided object
@bhaireshm
bhaireshm / getNestedValue.js
Last active February 24, 2025 09:22
Get nested value from the given object. It checks for the key first then returns the value.
/**
* Get nested value from the given object. It checks for the key first then returns the value.
*
* @param {object} d
* @param {string} k - key name separated by dot character
* @example
* const data = {
pid: 'some-id',
portions: { name: 'section' }
@bhaireshm
bhaireshm / getDatesInRange.js
Created June 26, 2023 09:30
Returns all the dates between the start date and end date, including both.
function getDatesInRange(startDate, endDate) {
if(!startDate || !endDate) return null;
startDate = new Date(startDate);
endDate = new Date(endDate);
const date = new Date(startDate.getTime());
const dates = [];
while (date <= endDate) {
dates.push(new Date(date));
@bhaireshm
bhaireshm / ezjs.md
Last active February 24, 2025 09:22
ez.js helper package

ez.js is more than just a library; it's a coding companion that simplifies complex tasks. Whether you're dealing with arrays, numbers, objects, or strings, ez.js has got your back! Say goodbye to coding hassles and hello to streamlined JavaScript magic.

This file has been truncated, but you can view the full file.
[
{"id":"52180","Regn_no":"11","Acft_Type":"38L","Flight_no":"9W2662","Source":"ATQ","Destination":"DEL","Flight_Date":"2021-05-28 00:00:00","STD":"2021-05-28 10:45:00","STA":"2021-05-28 11:55:00","ETD":"","ETA":"","ATD":"","ABN":"","TDN":"","ATA":"","CargoSpace":"3000"},
{"id":"52181","Regn_no":"11","Acft_Type":"38L","Flight_no":"9W2791","Source":"DEL","Destination":"ATQ","Flight_Date":"2021-05-28 00:00:00","STD":"2021-05-28 12:35:00","STA":"2021-05-28 13:45:00","ETD":"","ETA":"","ATD":"","ABN":"","TDN":"","ATA":"","CargoSpace":"3000"},
{"id":"52182","Regn_no":"11","Acft_Type":"3JU","Flight_no":"9W0431","Source":"BOM","Destination":"IXE","Flight_Date":"2021-05-28 00:00:00","STD":"2021-05-28 13:05:00","STA":"2021-05-28 14:35:00","ETD":"","ETA":"","ATD":"","ABN":"","TDN":"","ATA":"","CargoSpace":"3000"},
{"id":"52183","Regn_no":"11","Acft_Type":"38L","Flight_no":"9W0373","Source":"ATQ","Destination":"DEL","Flight_Date":"2021-05-28 00:00:00","STD":"2021-05-28 14:20:00","STA":"2021-05-28 15:30:00","ETD":"","ETA"
var prompt = require("prompt");
var parseString = require("xml2js").parseString;
const path = require("path");
const fs = require("fs");
start();
function start() {
prompt.start();
const { resolve, basename, join } = require("path");
const { rm, existsSync, mkdirSync, writeFileSync, readFileSync } = require("fs");
const prompt = require("prompt").start({ noHandleSIGINT: true });
const helperFolderpath = resolve(__dirname, "helper");
const base_url = "https://api.github.com/users";
const headers = { Authorization: "" };
let showLog = false;
let readJSON = true; // * Note: set this false to get the data latest from github.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Local IP Address</title>
</head>