pomeranian-durations
Version:
An immutable duration library based on the ISO-8601 format for durations.
18 lines (13 loc) • 2.92 kB
JavaScript
"use strict";
/* eslint-disable max-len */
var jsdoc2md = require('jsdoc-to-markdown');
var parsedDocs = jsdoc2md.getTemplateDataSync({
files: 'src/*.js'
});
var _require = require("./_generate_docs_helper"),
generateCategoryNavigation = _require.generateCategoryNavigation,
extractCategories = _require.extractCategories,
generateCategory = _require.generateCategory; // eslint-disable-next-line no-console
console.log(" \n# Pomeranian Durations \uD83D\uDC36\n\nAn immutable duration library based on the ISO-8601 format for durations.\n\n```\nnpm install pomeranian-durations --save\nyarn add pomeranian-durations\n```\n\n# Helpers\n\n".concat(generateCategoryNavigation(parsedDocs), "\n\n").concat(extractCategories(parsedDocs).map(function (category) {
return generateCategory(parsedDocs, category);
}).join('\n'), "\n\n# Handling parsing errors\n\nBy default this library returns 'Invalid Duration' when it can't parse the format.\nAs every application wants to handle those kinds of errors differently developers\ncan use functional composition to create their own verison of pomeranian durations.\n\n```js\nconst errorHandler = () => 'An error occured, our team is already on it.'\nconst addSchoolHour = pipe(\n addHours(1.5),\n whenInvalid(errorHandler)\n);\n\naddSchoolHour('PT1H') // => PT2.5H\naddSchoolHour('Invalid duration') // => 'An error occured, our team is already on it.'\n```\n\n# Upgrade to version 1.0.0\n\n- Swapped arguments of add* and subtract* functions, as they're now curried.\n```js\n// version 0.*\naddSeconds('PT1S', 1) // => PT2S\n\n// version 1.*\naddSeconds(1, 'PT1S') // => PT2S\naddSeconds(1)('PT1S') // => PT2S\n```\n- Wrapper got removed (please use regular functional composition instead)\n- Pomeranian durations return 'Invalid Duration' when it receives an invalid duration. It's up to the developer how this should be handled. This library provides a helper `whenInvalid` which can be used to handle those cases.\n\n```js\nimport { addSeconds as _addSeconds, whenInvalid } from 'pomeranian-durations';\n\nconst addSeconds1 = pipe(\n whenInvalid(() => 'PT0S'),\n _addSeconds(10),\n); // => PT10S\n\nconst addSeconds2 = pipe(\n _addSeconds(10),\n whenInvalid(() => 'PT0S'),\n); // => PT0S\n```\n\n# Precision Issues\n\nBecause date components (years, months, weeks, days) can't be converted to other unites without date and timezone information, `pomeranian-durations`\ndoesn't support them yet. To do precise arithmetic operations it is recommended to avoid years, months, weeks and days completely when using durations.\n\nFor more information have a look at http://www.ostyn.com/standards/scorm/samples/ISOTimeForSCORM.htm\n\n# Contributing\n\nAll contributions are very welcome. If you need help with the setup or if this library is missing \nsome features just create an issue or ping me on Twitter (@webpapaya). I'm happy to help you out.\n"));