A utility library for common operations such as string manipulation, object merging, and date/time formatting.
The UtilityLibrary
is not published as an npm package. To use it, simply include the utility files in your project and import them as needed.
import { reverseString, countSubstring, deepMerge, formatDate } from "./UtilityLibrary";
// Example usage
console.log(reverseString('hello')); // olleh
console.log(countSubstring('hello world', 'o')); // 2
console.log(formatDate(new Date(), 'Asia/Dhaka'));
const obj1 = {
a: 1,
b: 'hello',
c: {
d: 'world',
e: [1, 2, 3]
},
f: [4, 5]
};
const obj2 = {
b: 'updated',
c: {
e: [4, 5]
},
f: ['a', 'b'],
g: { h: 'test' }
};
console.log(deepMerge(obj1, obj2));
To clone the repository, use the following command:
git clone https://github.com/sakibhasancse/UtilityLibrary.git
To compile the TypeScript files and run the code, use the following command:
tsc index.ts && node index.js
This command compiles the index.ts
file into JavaScript and then runs the compiled index.js
file using Node.js.
Reverses a given string.
Counts the number of occurrences of a substring in a given string.
Deep merges two objects, handling nested objects and arrays.
Formats a date object to a string in the specified timezone.