js-utilities-libs
Advanced tools
Comparing version 1.0.2 to 1.0.3
50
index.js
@@ -1,5 +0,5 @@ | ||
// Ask user for the format of the date | ||
// Trim whitespace from both ends of a string | ||
function trim(str) { | ||
export function trim(str) { | ||
return str.trim(); | ||
@@ -9,3 +9,3 @@ } | ||
// Convert a string to camelCase | ||
function toCamelCase(str) { | ||
export function toCamelCase(str) { | ||
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()); | ||
@@ -15,3 +15,3 @@ } | ||
// Convert a string to snake_case | ||
function toSnakeCase(str) { | ||
export function toSnakeCase(str) { | ||
return str.replace(/[A-Z]/g, (match) => `_${match.toLowerCase()}`); | ||
@@ -21,3 +21,3 @@ } | ||
// Check if a string contains another string | ||
function contains(str, substring) { | ||
export function contains(str, substring) { | ||
return str.includes(substring); | ||
@@ -27,3 +27,3 @@ } | ||
// Sort an array of numbers in ascending order | ||
function sortArray(arr) { | ||
export function sortArray(arr) { | ||
return arr.sort((a, b) => a - b); | ||
@@ -33,3 +33,3 @@ } | ||
// Filter an array of numbers to get only even numbers | ||
function filterEvenNumbers(arr) { | ||
export function filterEvenNumbers(arr) { | ||
return arr.filter((num) => num % 2 === 0); | ||
@@ -39,3 +39,3 @@ } | ||
// Map an array of strings to uppercase | ||
function mapToUppercase(arr) { | ||
export function mapToUppercase(arr) { | ||
return arr.map((str) => str.toUpperCase()); | ||
@@ -45,3 +45,3 @@ } | ||
// Reduce an array of numbers to get the sum | ||
function sumArray(arr) { | ||
export function sumArray(arr) { | ||
return arr.reduce((acc, curr) => acc + curr, 0); | ||
@@ -51,3 +51,3 @@ } | ||
// Format a date object to a string | ||
function formatDate(date) { | ||
export function formatDate(date) { | ||
return `${date.getFullYear()}-${(date.getMonth() + 1) | ||
@@ -59,3 +59,3 @@ .toString() | ||
// Calculate the difference between two dates in days | ||
function dateDiffInDays(date1, date2) { | ||
export function dateDiffInDays(date1, date2) { | ||
const diffInMs = Math.abs(date2 - date1); | ||
@@ -66,3 +66,3 @@ return Math.floor(diffInMs / (1000 * 60 * 60 * 24)); | ||
// Generate a random number between a min and max value | ||
function getRandomNumber(min, max) { | ||
export function getRandomNumber(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
@@ -72,3 +72,3 @@ } | ||
// Calculate the average of an array of numbers | ||
function calculateAverage(arr) { | ||
export function calculateAverage(arr) { | ||
const sum = arr.reduce((acc, curr) => acc + curr, 0); | ||
@@ -79,3 +79,3 @@ return sum / arr.length; | ||
// Merge two objects into a new object | ||
function mergeObjects(obj1, obj2) { | ||
export function mergeObjects(obj1, obj2) { | ||
return { ...obj1, ...obj2 }; | ||
@@ -85,3 +85,3 @@ } | ||
// Clone an object | ||
function cloneObject(obj) { | ||
export function cloneObject(obj) { | ||
return { ...obj }; | ||
@@ -91,3 +91,3 @@ } | ||
// Check if an object has a specific property | ||
function hasProperty(obj, prop) { | ||
export function hasProperty(obj, prop) { | ||
return prop in obj; | ||
@@ -97,3 +97,3 @@ } | ||
// Validate an email address | ||
function validateEmail(email) { | ||
export function validateEmail(email) { | ||
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
@@ -104,3 +104,3 @@ return regex.test(email); | ||
// Validate a URL | ||
function validateURL(url) { | ||
export function validateURL(url) { | ||
const regex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i; | ||
@@ -111,3 +111,3 @@ return regex.test(url); | ||
// Read a file asynchronously | ||
function readFile(filePath) { | ||
export function readFile(filePath) { | ||
return new Promise((resolve, reject) => { | ||
@@ -125,3 +125,3 @@ fs.readFile(filePath, "utf8", (err, data) => { | ||
// Write to a file asynchronously | ||
function writeFile(filePath, data) { | ||
export function writeFile(filePath, data) { | ||
return new Promise((resolve, reject) => { | ||
@@ -139,3 +139,3 @@ fs.writeFile(filePath, data, "utf8", (err) => { | ||
// Make an HTTP GET request | ||
async function fetchData(url) { | ||
export async function fetchData(url) { | ||
const response = await fetch(url); | ||
@@ -149,3 +149,3 @@ if (!response.ok) { | ||
// Convert an object to JSON string | ||
function objectToJson(obj) { | ||
export function objectToJson(obj) { | ||
return JSON.stringify(obj); | ||
@@ -155,3 +155,3 @@ } | ||
// Parse a JSON string to an object | ||
function jsonToObject(jsonStr) { | ||
export function jsonToObject(jsonStr) { | ||
return JSON.parse(jsonStr); | ||
@@ -161,3 +161,3 @@ } | ||
// Log an error with a timestamp | ||
function logError(error) { | ||
export function logError(error) { | ||
console.error(`[${new Date().toISOString()}] ${error.message}`); | ||
@@ -167,4 +167,4 @@ } | ||
// Format an error message for display | ||
function formatErrorMessage(error) { | ||
export function formatErrorMessage(error) { | ||
return `An error occurred: ${error.message}`; | ||
} |
{ | ||
"name": "js-utilities-libs", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "js-utilities-libs is a JavaScript library that provides a collection of utility functions for common programming tasks. It includes functions for string manipulation, array operations, date and time handling, mathematical calculations, object manipulation, data validation, file and path operations, network utilities, data formatting, and error handling. Each function is designed to be simple, efficient, and versatile, making it easy to use in a wide range of projects.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -167,7 +167,7 @@ # js-utilities-libs | ||
1.0.2 | ||
1.0.3 | ||
## Author | ||
Name :Deepak Sharma | ||
Name : Deepak Sharma | ||
Email : uddibhardwaj08@gmail.com |
8971
122