Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esmile-useful

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esmile-useful - npm Package Compare versions

Comparing version 0.2.0-dev.0.0.2 to 0.2.0-dev.0.0.4

2

package.json
{
"name": "esmile-useful",
"version": "0.2.0-dev.0.0.2",
"version": "0.2.0-dev.0.0.4",
"description": "Esmile Utility",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -49,11 +49,18 @@ ## Installation

| Function | Description |
| ------------- | ------------------------------------------- |
| `formats` | Different types of text and number formats |
| `millisecond` | Converts the indicated time to milliseconds |
| `wait` | Execute the code after a while |
| `log` | Make a log with or without color |
| `type` | Check what type is provided |
| `random` | Get a random number between 2 numbers |
| `randomItem` | Get a random element from an array |
| `symbols` | Returns a selected symbol |
| Function | Description |
| -------------------------------------- | --------------------------------------------------------------------------- |
| `formats` | Different types of text and number formats |
|     `Number` | Formats a number to a string with thousand separators |
|     `TitleCase` | Formats a string to title case |
|     `SentenceCase` | Formats a string to sentence case |
|     `CamelCase` | Formats a string to camel case |
|     `KebabCase` | Formats a string to kebab case |
|     `SnakeCase` | Formats a string to snake case |
|     `DateFor` | Formats a date as a string with a customizable order of day, month and year |
| `millisecond` | Converts the indicated time to milliseconds |
| `wait` | Execute the code after a while |
| `log` | Make a log with or without color |
| `type` | Check what type is provided |
| `random` | Get a random number between 2 numbers |
| `randomItem` | Get a random element from an array |
| `symbols` | Returns a selected symbol |

@@ -74,2 +74,45 @@ /**

/**
* Formats a date as a string with a customizable order of day, month and year.
* @param {Date} date - The date to format.
* @param {string} [order="dmy"] - The order in which to display the day, month and year.
* Can be "dmy", "mdy", "ymd", "ydm", "myd" or "dym".
* @example
* console.log(formats.DateFor(new Date(), "dmy"))
* console.log(formats.DateFor(new Date(), "mdy"))
* console.log(formats.DateFor(new Date(), "ymd"))
* console.log(formats.DateFor(new Date(), "ydm"))
* console.log(formats.DateFor(new Date(), "myd"))
* console.log(formats.DateFor(new Date(), "dym"))
* @returns {string} A string representation of the date.
*/
function DateFor(date, order = "dmy") {
const day = date.getDate().toString().padStart(2, "0");
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const year = date.getFullYear();
let formattedDate;
switch (order) {
case "mdy":
formattedDate = `${month}/${day}/${year}`;
break;
case "ymd":
formattedDate = `${year}/${month}/${day}`;
break;
case "ydm":
formattedDate = `${year}/${day}/${month}`;
break;
case "myd":
formattedDate = `${month}/${year}/${day}`;
break;
case "dym":
formattedDate = `${day}/${year}/${month}`;
break;
default:
formattedDate = `${day}/${month}/${year}`;
}
return formattedDate;
}
/* Exporting the functions to be used in other files. */

@@ -83,2 +126,3 @@ module.exports = {

SnakeCase,
DateFor,
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc