New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@datatypes/duration

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datatypes/duration - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

readme.md

64

build/index.js

@@ -31,10 +31,10 @@ 'use strict';

var durationPattern = '^P' + '(?:(\\d+)Y)?' + // Years
'(?:(\\d+)M)?' + // Months
'(?:(\\d+)W)?' + // Weeks
'(?:(\\d+)D)?' + // Days
'T?' + '(?:(\\d+)H)?' + // Hours
'(?:(\\d+)M)?' + // Minutes
'(?:(\\d+)?' + // Seconds
'\\.?(\\d+)?S)?' + // Milliseconds
var durationPattern = '^P' + '(?:([0-9]+)Y)?' + // Years
'(?:([0-9]+)M)?' + // Months
'(?:([0-9]+)W)?' + // Weeks
'(?:([0-9]+)D)?' + // Days
'T?' + '(?:([0-9]+)H)?' + // Hours
'(?:([0-9]+)M)?' + // Minutes
'(?:([0-9]+)?' + // Seconds
'(?:\\.([0-9]{1,3}))?S)?' + // Milliseconds
'$';

@@ -47,2 +47,5 @@

// Milliseconds
durationArray[8] = Number('0.' + durationArray[8]) * 1000;
_fragments2.default.forEach(function (fragment, index) {

@@ -52,4 +55,3 @@ var value = Number(durationArray[index + 1]);

if (typeof value === 'number' && !Number.isNaN(value)) {
_this._precision = fragment.replace(/s$/, '');
_this[fragment] = value;
_this['_' + fragment] = value;
}

@@ -253,3 +255,17 @@ });

get: function get() {
return this._precision;
var _this2 = this;
var precision = void 0;
// Clone array as .reverse() is in place
Array.from(_fragments2.default).reverse().some(function (fragment) {
var value = _this2[fragment];
if (typeof value === 'number' && !Number.isNaN(value)) {
precision = fragment.replace(/s$/, '');
return true;
}
});
return precision;
},

@@ -280,24 +296,22 @@ set: function set(precision) {

get: function get() {
var _this2 = this;
var _this3 = this;
return _fragments2.default.reduce(function (string, fragment) {
if (_this2[fragment] == null) {
return _fragments2.default.reduce(function (string, fragment, fragmentIndex) {
if (typeof _this3[fragment] !== 'number' || Number.isNaN(_this3[fragment])) {
return string;
}
if (fragment === 'minutes' && !string.includes('t')) {
string += 't';
// fragmentIndex > 3 means smaller than day
if (!string.includes('T') && fragmentIndex > 3) {
string += 'T';
}
string += _this2[fragment] + fragment.substr(0, 1);
if (fragment === 'days') {
string += 't';
}
if (fragment === 'milliseconds') {
string.replace('s', '.' + _this2[fragment] + 's');
string = string.replace(/s$/, '.' + _this3.milliseconds + 'S');
} else {
string += _this3[fragment] + fragment.substr(0, 1);
}
return string;
}, 'p').replace(/t$/, '').toUpperCase();
}, 'p').toUpperCase();
}

@@ -307,6 +321,6 @@ }, {

get: function get() {
var _this3 = this;
var _this4 = this;
return _fragments2.default.reduce(function (object, fragment) {
if (_this3[fragment] != null) object[fragment] = _this3[fragment];
if (_this4[fragment] != null) object[fragment] = _this4[fragment];
return object;

@@ -313,0 +327,0 @@ }, {

{
"name": "@datatypes/duration",
"version": "0.3.0",
"version": "0.4.0",
"description": "Full ISO 8601 compatible duration class",

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

@@ -58,3 +58,3 @@ import runTest from 'ava'

{
string: test.title,
string: 'PT7H',
hours: 7,

@@ -83,3 +83,3 @@ isAccurate: true,

const referenceObject = {
string: 'P7HT30M',
string: 'PT7H30M',
hours: 7,

@@ -98,3 +98,3 @@ minutes: 30,

{
string: test.title,
string: 'PT7S',
seconds: 7,

@@ -111,3 +111,3 @@ isAccurate: true,

{
string: 'P7S345M',
string: 'PT7.345S',
seconds: 7,

@@ -120,2 +120,16 @@ milliseconds: 345,

runTest('P7.3S', test => {
expect(
new Duration(test.title).toObject(),
'to equal',
{
string: 'PT7.300S',
seconds: 7,
milliseconds: 300,
isAccurate: true,
}
)
})
runTest('P7Y5M', test => {

@@ -122,0 +136,0 @@ expect(

import runTest from 'ava'
import expect from 'unexpected'
import Duration from '../source/index.js'
import Duration from '../source/index'

@@ -10,2 +10,7 @@ runTest('precision of P7D is day', test => {

runTest('precision of P5Y is year', test => {
const duration = new Duration('P5Y')
expect(duration.precision, 'to equal', 'year')
})
runTest('precision of P7D0H is hour', test => {

@@ -12,0 +17,0 @@ const duration = new Duration('P7D0H')

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