mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 12:36:01 +00:00
fix
This commit is contained in:
104
node_modules/iso8601-duration/README.md
generated
vendored
Normal file
104
node_modules/iso8601-duration/README.md
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
# ISO8601-duration
|
||||
Node/Js-module for parsing and making sense of ISO8601-durations
|
||||
|
||||
[][1]
|
||||
[][2]
|
||||
[][3]
|
||||
|
||||
## The ISO8601 duration format
|
||||
|
||||
Durations in ISO8601 comes in two formats:
|
||||
* **`PnYnMnDTnHnMnS`** - `P<date>T<time>`
|
||||
The `n` is replaced by the value for each of the date and time elements that follow the `n`.
|
||||
Leading zeros are not required
|
||||
* **`PnW`** - the week format
|
||||
|
||||
|
||||
Check out the details on [Wikipedia](https://en.wikipedia.org/wiki/ISO_8601#Durations)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install iso8601-duration
|
||||
```
|
||||
|
||||
## Usage
|
||||
Most noteworthy of the interface is the ability to provide a `date` for `toSeconds`-calculations.
|
||||
Why becomes evident when working with durations that span dates as all months are not equally long.
|
||||
E.g January of 2016 is **744 hours** compared to the **696 hours** of February 2016.
|
||||
|
||||
If a date is not provided for `toSeconds` the timestamp `Date.now()` is used as baseline.
|
||||
|
||||
### Interface
|
||||
|
||||
```js
|
||||
export const toSeconds; // fn = (obj, date?) => number
|
||||
export const pattern; // ISO8601 RegExp
|
||||
export const parse; // fn = string => obj
|
||||
export default {
|
||||
toSeconds,
|
||||
pattern,
|
||||
parse
|
||||
}
|
||||
```
|
||||
|
||||
### Example
|
||||
Simple usage
|
||||
```js
|
||||
import {parse, end, toSeconds, pattern} from 'iso8601-duration';
|
||||
|
||||
console.log(parse('P1Y2M4DT20H44M12.67S'));
|
||||
/* outputs =>
|
||||
{
|
||||
years: 1,
|
||||
months: 2,
|
||||
days: 4,
|
||||
hours: 20,
|
||||
minutes: 44,
|
||||
seconds: 12.67
|
||||
}
|
||||
*/
|
||||
|
||||
console.log( toSeconds( parse('PT1H30M10.5S') ) );
|
||||
// outputs => 5410.5
|
||||
|
||||
console.log ( end( parse('P1D') ) );
|
||||
// outputs => DateObj 2017-10-04T10:14:50.190Z
|
||||
|
||||
```
|
||||
|
||||
A more complete usecase / example
|
||||
```js
|
||||
import {parse, toSeconds, pattern} from 'iso8601-duration';
|
||||
|
||||
// convert iso8601 duration-strings to total seconds from some api
|
||||
const getWithSensibleDurations = someApiEndpoint => {
|
||||
// return promise, like fetch does
|
||||
return new Promise(resolve => {
|
||||
// fetch text
|
||||
fetch(someApiEndpoint)
|
||||
.then(res => res.text())
|
||||
.then(jsonString => {
|
||||
|
||||
// create new pattern that matches on surrounding double-quotes
|
||||
// so we can replace the string with an actual number
|
||||
const replacePattern = new RegExp(`\\"${pattern.source}\\"`, 'g');
|
||||
jsonString = jsonString.replace(replacePattern, m => {
|
||||
return toSeconds(parse(m));
|
||||
});
|
||||
// resolve original request with sensible durations in object
|
||||
resolve( JSON.parse(jsonString) );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT @ https://tolu.mit-license.org/
|
||||
|
||||
[1]: https://github.com/sindresorhus/xo "xo on github"
|
||||
[2]: https://travis-ci.org/tolu/ISO8601-duration "travis build status"
|
||||
[3]: https://www.npmjs.com/package/iso8601-duration "npm package"
|
23
node_modules/iso8601-duration/index.d.ts
generated
vendored
Normal file
23
node_modules/iso8601-duration/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
export interface Duration {
|
||||
years?: number;
|
||||
months?: number;
|
||||
days?: number;
|
||||
hours?: number;
|
||||
minutes?: number;
|
||||
seconds?: number;
|
||||
weeks?: number;
|
||||
}
|
||||
|
||||
export const pattern: RegExp;
|
||||
export function parse(durationString: string): Duration;
|
||||
export function end(duration: Duration, startDate?: Date): Date;
|
||||
export function toSeconds(duration: Duration, startDate?: Date): number;
|
||||
|
||||
declare const _default: {
|
||||
end: typeof end;
|
||||
toSeconds: typeof toSeconds;
|
||||
pattern: typeof pattern;
|
||||
parse: typeof parse;
|
||||
};
|
||||
|
||||
export default _default;
|
87
node_modules/iso8601-duration/lib/index.js
generated
vendored
Normal file
87
node_modules/iso8601-duration/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
/**
|
||||
* @description A module for parsing ISO8601 durations
|
||||
*/
|
||||
|
||||
/**
|
||||
* The pattern used for parsing ISO8601 duration (PnYnMnDTnHnMnS).
|
||||
* This does not cover the week format PnW.
|
||||
*/
|
||||
|
||||
// PnYnMnDTnHnMnS
|
||||
var numbers = '\\d+(?:[\\.,]\\d+)?';
|
||||
var weekPattern = '(' + numbers + 'W)';
|
||||
var datePattern = '(' + numbers + 'Y)?(' + numbers + 'M)?(' + numbers + 'D)?';
|
||||
var timePattern = 'T(' + numbers + 'H)?(' + numbers + 'M)?(' + numbers + 'S)?';
|
||||
|
||||
var iso8601 = 'P(?:' + weekPattern + '|' + datePattern + '(?:' + timePattern + ')?)';
|
||||
var objMap = ['weeks', 'years', 'months', 'days', 'hours', 'minutes', 'seconds'];
|
||||
|
||||
/**
|
||||
* The ISO8601 regex for matching / testing durations
|
||||
*/
|
||||
var pattern = exports.pattern = new RegExp(iso8601);
|
||||
|
||||
/** Parse PnYnMnDTnHnMnS format to object
|
||||
* @param {string} durationString - PnYnMnDTnHnMnS formatted string
|
||||
* @return {Object} - With a property for each part of the pattern
|
||||
*/
|
||||
var parse = exports.parse = function parse(durationString) {
|
||||
// Slice away first entry in match-array
|
||||
return durationString.match(pattern).slice(1).reduce(function (prev, next, idx) {
|
||||
prev[objMap[idx]] = parseFloat(next) || 0;
|
||||
return prev;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert ISO8601 duration object to an end Date.
|
||||
*
|
||||
* @param {Object} duration - The duration object
|
||||
* @param {Date} startDate - The starting Date for calculating the duration
|
||||
* @return {Date} - The resulting end Date
|
||||
*/
|
||||
var end = exports.end = function end(duration, startDate) {
|
||||
// Create two equal timestamps, add duration to 'then' and return time difference
|
||||
var timestamp = startDate ? startDate.getTime() : Date.now();
|
||||
var then = new Date(timestamp);
|
||||
|
||||
then.setFullYear(then.getFullYear() + duration.years);
|
||||
then.setMonth(then.getMonth() + duration.months);
|
||||
then.setDate(then.getDate() + duration.days);
|
||||
then.setHours(then.getHours() + duration.hours);
|
||||
then.setMinutes(then.getMinutes() + duration.minutes);
|
||||
// Then.setSeconds(then.getSeconds() + duration.seconds);
|
||||
then.setMilliseconds(then.getMilliseconds() + duration.seconds * 1000);
|
||||
// Special case weeks
|
||||
then.setDate(then.getDate() + duration.weeks * 7);
|
||||
|
||||
return then;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert ISO8601 duration object to seconds
|
||||
*
|
||||
* @param {Object} duration - The duration object
|
||||
* @param {Date} startDate - The starting point for calculating the duration
|
||||
* @return {Number}
|
||||
*/
|
||||
var toSeconds = exports.toSeconds = function toSeconds(duration, startDate) {
|
||||
var timestamp = startDate ? startDate.getTime() : Date.now();
|
||||
var now = new Date(timestamp);
|
||||
var then = end(duration, now);
|
||||
|
||||
var seconds = (then.getTime() - now.getTime()) / 1000;
|
||||
return seconds;
|
||||
};
|
||||
|
||||
exports.default = {
|
||||
end: end,
|
||||
toSeconds: toSeconds,
|
||||
pattern: pattern,
|
||||
parse: parse
|
||||
};
|
87
node_modules/iso8601-duration/package.json
generated
vendored
Normal file
87
node_modules/iso8601-duration/package.json
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"_from": "iso8601-duration@^1.0.0",
|
||||
"_id": "iso8601-duration@1.2.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-ErTBd++b17E8nmWII1K1uZtBgD1E8RjyvwmxlCjPHNqHMD7gmcMHOw0E8Ro/6+QT4PhHRSnnMo7bxa1vFPkwhg==",
|
||||
"_location": "/iso8601-duration",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "iso8601-duration@^1.0.0",
|
||||
"name": "iso8601-duration",
|
||||
"escapedName": "iso8601-duration",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/simple-youtube-api"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/iso8601-duration/-/iso8601-duration-1.2.0.tgz",
|
||||
"_shasum": "5fa6fc180a8fe95ad6a6721c9bdd9069cb59e80e",
|
||||
"_spec": "iso8601-duration@^1.0.0",
|
||||
"_where": "C:\\Users\\matia\\Bot Files\\node_modules\\simple-youtube-api",
|
||||
"author": {
|
||||
"name": "Tobias Lundin"
|
||||
},
|
||||
"ava": {
|
||||
"files": [
|
||||
"test/*.js"
|
||||
],
|
||||
"failFast": true,
|
||||
"verbose": true,
|
||||
"require": [
|
||||
"babel-core/register"
|
||||
]
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/tolu/ISO8601-duration/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Node/Js-module for parsing and making sense of ISO8601-durations",
|
||||
"devDependencies": {
|
||||
"ava": "^0.22.0",
|
||||
"babel-cli": "^6.4.0",
|
||||
"babel-preset-es2015": "^6.3.13",
|
||||
"onchange": "^3.2.1",
|
||||
"snazzy": "^7.0.0",
|
||||
"standard": "^10.0.3",
|
||||
"typescript": "^3.0.3"
|
||||
},
|
||||
"files": [
|
||||
"src/index.js",
|
||||
"lib/index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"homepage": "https://github.com/tolu/ISO8601-duration#readme",
|
||||
"jsnext:main": "src/index.js",
|
||||
"keywords": [
|
||||
"ISO8601",
|
||||
"duration",
|
||||
"time"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"name": "iso8601-duration",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tolu/ISO8601-duration.git"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "babel -d lib/ src/",
|
||||
"lint": "standard | snazzy",
|
||||
"patch-release": "npm test && npm version patch && git push --follow-tags",
|
||||
"prepublishOnly": "npm run compile",
|
||||
"test": "npm run lint && ava && tsc",
|
||||
"watch": "onchange '**/*.js' -- npm run test"
|
||||
},
|
||||
"standard": {
|
||||
"ignore": [
|
||||
"lib/*.js"
|
||||
]
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "1.2.0"
|
||||
}
|
82
node_modules/iso8601-duration/src/index.js
generated
vendored
Normal file
82
node_modules/iso8601-duration/src/index.js
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @description A module for parsing ISO8601 durations
|
||||
*/
|
||||
|
||||
/**
|
||||
* The pattern used for parsing ISO8601 duration (PnYnMnDTnHnMnS).
|
||||
* This does not cover the week format PnW.
|
||||
*/
|
||||
|
||||
// PnYnMnDTnHnMnS
|
||||
const numbers = '\\d+(?:[\\.,]\\d+)?'
|
||||
const weekPattern = `(${numbers}W)`
|
||||
const datePattern = `(${numbers}Y)?(${numbers}M)?(${numbers}D)?`
|
||||
const timePattern = `T(${numbers}H)?(${numbers}M)?(${numbers}S)?`
|
||||
|
||||
const iso8601 = `P(?:${weekPattern}|${datePattern}(?:${timePattern})?)`
|
||||
const objMap = ['weeks', 'years', 'months', 'days', 'hours', 'minutes', 'seconds']
|
||||
|
||||
/**
|
||||
* The ISO8601 regex for matching / testing durations
|
||||
*/
|
||||
export const pattern = new RegExp(iso8601)
|
||||
|
||||
/** Parse PnYnMnDTnHnMnS format to object
|
||||
* @param {string} durationString - PnYnMnDTnHnMnS formatted string
|
||||
* @return {Object} - With a property for each part of the pattern
|
||||
*/
|
||||
export const parse = durationString => {
|
||||
// Slice away first entry in match-array
|
||||
return durationString.match(pattern).slice(1).reduce((prev, next, idx) => {
|
||||
prev[objMap[idx]] = parseFloat(next) || 0
|
||||
return prev
|
||||
}, {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ISO8601 duration object to an end Date.
|
||||
*
|
||||
* @param {Object} duration - The duration object
|
||||
* @param {Date} startDate - The starting Date for calculating the duration
|
||||
* @return {Date} - The resulting end Date
|
||||
*/
|
||||
export const end = (duration, startDate) => {
|
||||
// Create two equal timestamps, add duration to 'then' and return time difference
|
||||
const timestamp = (startDate ? startDate.getTime() : Date.now())
|
||||
const then = new Date(timestamp)
|
||||
|
||||
then.setFullYear(then.getFullYear() + duration.years)
|
||||
then.setMonth(then.getMonth() + duration.months)
|
||||
then.setDate(then.getDate() + duration.days)
|
||||
then.setHours(then.getHours() + duration.hours)
|
||||
then.setMinutes(then.getMinutes() + duration.minutes)
|
||||
// Then.setSeconds(then.getSeconds() + duration.seconds);
|
||||
then.setMilliseconds(then.getMilliseconds() + (duration.seconds * 1000))
|
||||
// Special case weeks
|
||||
then.setDate(then.getDate() + (duration.weeks * 7))
|
||||
|
||||
return then
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ISO8601 duration object to seconds
|
||||
*
|
||||
* @param {Object} duration - The duration object
|
||||
* @param {Date} startDate - The starting point for calculating the duration
|
||||
* @return {Number}
|
||||
*/
|
||||
export const toSeconds = (duration, startDate) => {
|
||||
const timestamp = (startDate ? startDate.getTime() : Date.now())
|
||||
const now = new Date(timestamp)
|
||||
const then = end(duration, now)
|
||||
|
||||
const seconds = (then.getTime() - now.getTime()) / 1000
|
||||
return seconds
|
||||
}
|
||||
|
||||
export default {
|
||||
end,
|
||||
toSeconds,
|
||||
pattern,
|
||||
parse
|
||||
}
|
Reference in New Issue
Block a user