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

date-template

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date-template - npm Package Compare versions

Comparing version 2.0.9 to 2.0.10

test-benchmark.js

10

package.json
{
"name": "date-template",
"version": "2.0.9",
"description": "Easy function for returning date by template.",
"version": "2.0.10",
"description": "Easy function for returning date by template",
"main": "index.js",

@@ -20,3 +20,7 @@ "author": "serg <ss0sergey@gmail.com>",

"template"
]
],
"devDependencies": {
"benchmark": "^2.1.4",
"moment": "^2.19.1"
}
}

@@ -6,2 +6,3 @@ # date-template

1. Change the date type
1. No dependencies

@@ -21,3 +22,3 @@ ### install

- ```%ms``` milliseconds
- ```%0``` [special prefix](#special-prifix) for all template types
- ```%0``` [special prefix](#special-prefix) for all template types

@@ -29,4 +30,6 @@ ### use

```javascript
/* return new Date */
var dateTemplate = require('date-template')
// return new Date
dateTemplate('%h:%m:%s')

@@ -41,4 +44,4 @@ // "20:9:7"

dateTemplate('hours:%h minutes:%m seconds:%s')
// "hours:22 minutes:9 seconds:7"
dateTemplate('hourse:%h minutes:%m seconds:%s')
// "hourse:22 minutes:9 seconds:7"

@@ -52,4 +55,12 @@ dateTemplate('%0h:WOW:%0m')

```javascript
/* return other Date */
var dateTemplate = require('date-template')
// return other Date
var oldDate = new Date()
oldDate.setHours(oldDate.getHours() -3)
dateTemplate('%0h:%0m:%0s', oldDate)
// "17:09:07"
var milliseconds = +new Date()

@@ -61,8 +72,4 @@ // 1499015643673

var oldDate = new Date()
oldDate.setHours(-3)
dateTemplate('%0h:%0m:%0s', oldDate)
// "17:09:07"
dateTemplate('%M %D %Y, %h:%m:%s', '2017-07-10T14:11:34+0300')
// "7 10 2017, 14:11:34"
```

@@ -74,4 +81,6 @@

```javascript
/* return Date to user format */
var dateTemplate = require('date-template')
// return Date to user format
var middlewareMount = (date) => {

@@ -97,3 +106,3 @@ var mounth = [

dateTemplate('Today is %M %D, %Y', false, middlewareMount)
dateTemplate('Today is ~M~ ~D~, ~Y~', false, middlewareMount)
// "Today is July 2, 2017"

@@ -123,3 +132,3 @@ ```

##### special prifix
##### special prefix
```javascript

@@ -132,2 +141,12 @@ dateTemplate('%h:%m:%s')

### [benchmark](https://benchmarkjs.com/) compare moment js
[node js test](https://github.com/SergProduction/date-template/blob/master/test-benchmark.js)
```
dateTemplate("%M %D %Y, %h:%m:%s") x 162,318 ops/sec ±5.79% (83 runs sampled)
moment().format("MMMM Do YYYY, h:mm:ss a") x 104,363 ops/sec ±9.36% (77 runs sampled)
Fastest is dateTemplate("%M %D %Y, %h:%m:%s")
```
### source code

@@ -143,5 +162,5 @@ ```javascript

h: { key: /%0?h/g, value: date.getHours(), }, // hourse
m: { key: /%0?m/g, value: date.getMinutes(), }, // minutes;
s: { key: /%0?s/g, value: date.getSeconds(), }, // seconds
ms: { key: /%0?ms/g, value: date.getMilliseconds(), }, // milliseconds
m: { key: /%0?m/g, value: date.getMinutes(), }, // minutes;
}

@@ -148,0 +167,0 @@ tmp = middleware ? middleware(tmp) : tmp

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