@hig/timestamp
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -113,2 +113,3 @@ import React from 'react'; | ||
plural, | ||
relativeTimeFormatOptions, | ||
timeDescriptors, | ||
@@ -120,2 +121,3 @@ timestamp | ||
const nowAsSeconds = new Date().valueOf() / 1000; | ||
const rtf = new Intl.RelativeTimeFormat(relativeTimeFormatOptions === null || relativeTimeFormatOptions === void 0 ? void 0 : relativeTimeFormatOptions.locales, relativeTimeFormatOptions === null || relativeTimeFormatOptions === void 0 ? void 0 : relativeTimeFormatOptions.options); | ||
const timeDifference = nowAsSeconds - asSeconds; | ||
@@ -154,3 +156,3 @@ let distance; | ||
return getTimestampSequence(distance, ellapsedDescriptor); | ||
return relativeTimeFormatOptions ? rtf.format(-distance, ellapsedDescriptor) : getTimestampSequence(distance, ellapsedDescriptor); | ||
}; | ||
@@ -190,2 +192,19 @@ | ||
/** | ||
* These are the options passed to the | ||
* Intl.RelativeTimeFormat() constructor | ||
* If this prop is used then the following props | ||
* will be ignored: plural, timestampSequence, | ||
* timeDescriptors, wordspace | ||
*/ | ||
relativeTimeFormatOptions: PropTypes.shape({ | ||
locales: PropTypes.string, | ||
options: PropTypes.shape({ | ||
localeMatcher: PropTypes.string, | ||
numberingSystem: PropTypes.string, | ||
style: PropTypes.string, | ||
numeric: PropTypes.string | ||
}) | ||
}), | ||
/** | ||
* Adds custom/overriding styles | ||
@@ -242,103 +261,3 @@ */ | ||
}; | ||
Timestamp.__docgenInfo = { | ||
"description": "", | ||
"displayName": "Timestamp", | ||
"props": { | ||
"plural": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want to pluralize the elapsed time unit\nIf \"true\" then it adds an \"s\" to the end of the time unit", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
}, | ||
"stylesheet": { | ||
"type": { | ||
"name": "func" | ||
}, | ||
"required": false, | ||
"description": "Adds custom/overriding styles" | ||
}, | ||
"timeDescriptors": { | ||
"type": { | ||
"name": "shape", | ||
"value": { | ||
"second": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"minute": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"hour": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"day": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"week": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"month": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"year": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"ago": { | ||
"name": "string", | ||
"required": false | ||
} | ||
} | ||
}, | ||
"required": false, | ||
"description": "An object that allows for localization of all the time words used\nBy default the object property name is the same as the property value\nProperty names: second, minute, hour, day, week, month, year, ago", | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\",\n}", | ||
"computed": false | ||
} | ||
}, | ||
"timestamp": { | ||
"type": { | ||
"name": "string" | ||
}, | ||
"required": false, | ||
"description": "ISO date string" | ||
}, | ||
"timestampSequence": { | ||
"type": { | ||
"name": "enum", | ||
"computed": true, | ||
"value": "availableSequences" | ||
}, | ||
"required": false, | ||
"description": "The sequence in which the timestamp is displayed\nie. 4 seconds ago (abc)", | ||
"defaultValue": { | ||
"value": "availableSequences.ABC", | ||
"computed": true | ||
} | ||
}, | ||
"wordSpace": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want a space between words", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
} | ||
} | ||
}; | ||
export { availableSequences, Timestamp as default, sequences }; |
@@ -123,2 +123,3 @@ 'use strict'; | ||
plural, | ||
relativeTimeFormatOptions, | ||
timeDescriptors, | ||
@@ -130,2 +131,3 @@ timestamp | ||
const nowAsSeconds = new Date().valueOf() / 1000; | ||
const rtf = new Intl.RelativeTimeFormat(relativeTimeFormatOptions === null || relativeTimeFormatOptions === void 0 ? void 0 : relativeTimeFormatOptions.locales, relativeTimeFormatOptions === null || relativeTimeFormatOptions === void 0 ? void 0 : relativeTimeFormatOptions.options); | ||
const timeDifference = nowAsSeconds - asSeconds; | ||
@@ -164,3 +166,3 @@ let distance; | ||
return getTimestampSequence(distance, ellapsedDescriptor); | ||
return relativeTimeFormatOptions ? rtf.format(-distance, ellapsedDescriptor) : getTimestampSequence(distance, ellapsedDescriptor); | ||
}; | ||
@@ -200,2 +202,19 @@ | ||
/** | ||
* These are the options passed to the | ||
* Intl.RelativeTimeFormat() constructor | ||
* If this prop is used then the following props | ||
* will be ignored: plural, timestampSequence, | ||
* timeDescriptors, wordspace | ||
*/ | ||
relativeTimeFormatOptions: PropTypes__default["default"].shape({ | ||
locales: PropTypes__default["default"].string, | ||
options: PropTypes__default["default"].shape({ | ||
localeMatcher: PropTypes__default["default"].string, | ||
numberingSystem: PropTypes__default["default"].string, | ||
style: PropTypes__default["default"].string, | ||
numeric: PropTypes__default["default"].string | ||
}) | ||
}), | ||
/** | ||
* Adds custom/overriding styles | ||
@@ -252,102 +271,2 @@ */ | ||
}; | ||
Timestamp.__docgenInfo = { | ||
"description": "", | ||
"displayName": "Timestamp", | ||
"props": { | ||
"plural": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want to pluralize the elapsed time unit\nIf \"true\" then it adds an \"s\" to the end of the time unit", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
}, | ||
"stylesheet": { | ||
"type": { | ||
"name": "func" | ||
}, | ||
"required": false, | ||
"description": "Adds custom/overriding styles" | ||
}, | ||
"timeDescriptors": { | ||
"type": { | ||
"name": "shape", | ||
"value": { | ||
"second": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"minute": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"hour": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"day": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"week": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"month": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"year": { | ||
"name": "string", | ||
"required": false | ||
}, | ||
"ago": { | ||
"name": "string", | ||
"required": false | ||
} | ||
} | ||
}, | ||
"required": false, | ||
"description": "An object that allows for localization of all the time words used\nBy default the object property name is the same as the property value\nProperty names: second, minute, hour, day, week, month, year, ago", | ||
"defaultValue": { | ||
"value": "{\n second: \"second\",\n minute: \"minute\",\n hour: \"hour\",\n day: \"day\",\n week: \"week\",\n month: \"month\",\n year: \"year\",\n ago: \"ago\",\n}", | ||
"computed": false | ||
} | ||
}, | ||
"timestamp": { | ||
"type": { | ||
"name": "string" | ||
}, | ||
"required": false, | ||
"description": "ISO date string" | ||
}, | ||
"timestampSequence": { | ||
"type": { | ||
"name": "enum", | ||
"computed": true, | ||
"value": "availableSequences" | ||
}, | ||
"required": false, | ||
"description": "The sequence in which the timestamp is displayed\nie. 4 seconds ago (abc)", | ||
"defaultValue": { | ||
"value": "availableSequences.ABC", | ||
"computed": true | ||
} | ||
}, | ||
"wordSpace": { | ||
"type": { | ||
"name": "bool" | ||
}, | ||
"required": false, | ||
"description": "If you want a space between words", | ||
"defaultValue": { | ||
"value": "true", | ||
"computed": false | ||
} | ||
} | ||
} | ||
}; | ||
@@ -354,0 +273,0 @@ exports.availableSequences = availableSequences; |
{ | ||
"name": "@hig/timestamp", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "HIG Timestamp", | ||
@@ -5,0 +5,0 @@ "author": "Autodesk Inc.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19598
4
452
1