parsehttpdate
Advanced tools
Comparing version 1.0.1 to 1.0.2
MIT License | ||
Copyright (c) 2018 Pimm "de Chinchilla" Hogeling | ||
Copyright (c) 2018, 2019 Pimm "de Chinchilla" Hogeling | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Tue, 15 Nov 1994 08:12:31 GMT | ||
* > Tue, 15 Nov 1994 08:12:31 GMT | ||
* | ||
@@ -11,11 +11,8 @@ * This format is a subset of the specification used by the Internet Message Format. Note that the specification also | ||
* | ||
* @param {string} value - The date-time, represented as a string in a certain format. | ||
* @param {boolean=} validate - Whether the passed date-time should be validated before being parsed. Not validating | ||
* (false) is faster, but behaviour is undefined if the passed date-time is not formatted | ||
* correctly. Validating (true, default) causes an error to be thrown if the passed | ||
* date-time is not formatted correctly. | ||
* @return {Date} The parsed date-time. | ||
* The second argument determines whether the passed date-time should be validated before being parsed. Not validating | ||
* (`false`) is faster, but behaviour is undefined if the passed date-time is not formatted correctly. Validating | ||
* (`true`, default) causes an error to be thrown if the passed date-time is not formatted correctly. | ||
*/ | ||
declare function parseHttpDate(value: string, validate?: boolean): Date; | ||
export = parseHttpDate; | ||
export default parseHttpDate; |
21
index.js
@@ -17,8 +17,12 @@ // (The number of seconds may start with a 6 because of leap seconds.) | ||
* | ||
* Tue, 15 Nov 1994 08:12:31 GMT | ||
* > Tue, 15 Nov 1994 08:12:31 GMT | ||
* | ||
* This format is a subset of the specification used by the Internet Message Format. Note that the specification also | ||
* defines two obsolete formats, which this implementation does not support. | ||
* | ||
* The second argument determines whether the passed date-time should be validated before being parsed. Not validating | ||
* (`false`) is faster, but behaviour is undefined if the passed date-time is not formatted correctly. Validating | ||
* (`true`, default) causes an error to be thrown if the passed date-time is not formatted correctly. | ||
*/ | ||
module.exports = function parseHttpDate(value, validate) { | ||
export default function parseHttpDate(value, validate) { | ||
if (false != validate) { | ||
@@ -29,13 +33,12 @@ if (false == validDateMatcher.test(value)) { | ||
} | ||
return new Date(Date.UTC( | ||
parseInt(value.substr(12, 4), 10), | ||
parseInt(value.substring(12, 16), 10), | ||
// (Skip over the first character of the month abbreviation, as we can safely detect the name by the second and | ||
// third character only.) | ||
monthsNames.indexOf(value.substr(9, 2)) >> 1, | ||
parseInt(value.substr(5, 2), 10), | ||
parseInt(value.substr(17, 2), 10), | ||
parseInt(value.substr(20, 2), 10), | ||
parseInt(value.substr(23, 2), 10) | ||
monthsNames.indexOf(value.substring(9, 11)) >> 1, | ||
parseInt(value.substring(5, 7), 10), | ||
parseInt(value.substring(17, 19), 10), | ||
parseInt(value.substring(20, 22), 10), | ||
parseInt(value.substring(23, 25), 10) | ||
)); | ||
}; |
{ | ||
"name": "parsehttpdate", | ||
"version": "1.0.1", | ||
"description": "Parses the value of the Date header in HTTP responses.", | ||
"description": "Parses the value of the Date header in HTTP responses", | ||
"version": "1.0.2", | ||
"main": "compiled/cjs/parsehttpdate.min.js", | ||
"module": "compiled/esm/parsehttpdate.min.js", | ||
"unpkg": "compiled/iife/parsehttpdatet.min.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"compiled", | ||
"index.d.ts", | ||
"copying.txt", | ||
"readme-nl.md" | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.4.5", | ||
"jest": "^24.8.0", | ||
"rollup": "^1.15.6", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-babel-minify": "^8.0.0", | ||
"typescript": "^3.5.2" | ||
}, | ||
"scripts": { | ||
"build": "rollup --config rollup.config.js", | ||
"test": "npm run-script build && jest && tsc --strict --noEmit test/type-test.ts", | ||
"coverage": "npm run-script build && jest --coverage --coverageReporters=text-lcov | coveralls" | ||
}, | ||
"author": { | ||
"name": "Pimm \"de Chinchilla\" Hogeling", | ||
"url": "https://null.house" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Pimm/parseHttpDate.git" | ||
}, | ||
"keywords": [ | ||
@@ -10,16 +43,3 @@ "http", | ||
"last-modified" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Pimm/parseHttpDate.git" | ||
}, | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"license": "X11", | ||
"devDependencies": { | ||
"jest": "^23.6.0" | ||
} | ||
] | ||
} |
@@ -1,14 +0,27 @@ | ||
# parseHttpDate | ||
Ontleedt de waarde van de `Date` header in HTTP antwoorden. | ||
Ontleedt datum-tijdstippen die zijn opgeschreven in het aangeraden formaat [gedefinieerd door HTTP/1.1](https://tools.ietf.org/html/rfc7231#section-7.1.1.1). Een voorbeeld van zo een datum-tijdstip is: | ||
## Omschrijving | ||
Ontleedt datum-tijdstippen van HTTP-headers zoals _Date_, _Last-Modified_, en _Expires_. Die datum-tijdstippen zijn bijna altijd opgeschreven in het aangeraden formaat [gedefinieerd door HTTP/1.1](https://tools.ietf.org/html/rfc7231#section-7.1.1.1). Een voorbeeld van zo een datum-tijdstip is: | ||
> Tue, 15 Nov 1994 08:12:31 GMT | ||
Dit formaat zie je terug in HTTP-headers zoals _Date_, _Last-Modified_, en _Expires_. Het is een subgroep van de specificatie die wordt gebruikt door in het [Internet Message Format](https://tools.ietf.org/html/rfc5322). Let op: de HTTP/1.1-specificatie definieert ook twee verouderde formaten die niet worden ondersteund door deze implementatie. | ||
Dit formaat is een subgroep van de specificatie die wordt gebruikt door in het [Internet Message Format](https://tools.ietf.org/html/rfc5322). | ||
## Gebruik | ||
# Installatie | ||
Installeer `parsehttpdate` met npm of Yarn en importeer de functie: | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
``` | ||
Als alternatief kan `parsehttpdate` ook worden binnengehaald met unpkg: | ||
```html | ||
<script src="https://unpkg.com/parsehttpdate@^1.0.2"></script> | ||
``` | ||
Met deze aanpak wordt de functie beschikbaar als `window.parseHttpDate`. | ||
# Gebruik | ||
```javascript | ||
parseHttpDate('Wed, 21 Oct 2015 07:28:00 GMT'); | ||
@@ -63,8 +76,6 @@ ``` | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
parseHttpDate('Wed, 21 Oct 2015 07:28:00 GMT', false); | ||
``` | ||
## ISO 8601 tijdsaanduiding | ||
## Andere formaten | ||
@@ -75,3 +86,3 @@ Ziet jouw datum-tijdstip er niet uit zoals het voorbeeld hierboven, maar meer zo? | ||
Gefeliciteerd: jouw datum-tijdstip is opgeschreven in het [ISO 8601](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15)-formaat. _Je hebt parseHttpDate niet nodig_. Je hebt geen enkele bibliotheek nodig. | ||
Gefeliciteerd: jouw datum-tijdstip is opgeschreven in het [ISO 8601](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15)-formaat. _Je hebt parseHttpDate niet nodig_. Je hebt geen enkele bibliotheek nodig: | ||
@@ -82,4 +93,12 @@ ```javascript | ||
De HTTP/1.1-specificatie definieert ook twee verouderde formaten naast het aangerade formaat van de bovengenoemde voorbeelden: | ||
> Sunday, 06-Nov-94 08:49:37 GMT | ||
> Sun Nov 6 08:49:37 1994 | ||
Deze implementatie ondersteunt deze niet. | ||
## Licentie (X11/MIT) | ||
Copyright (c) 2018 Pimm "de Chinchilla" Hogeling | ||
Copyright (c) 2018, 2019 Pimm "de Chinchilla" Hogeling | ||
@@ -90,2 +109,2 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
**The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** | ||
**The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** |
@@ -1,14 +0,27 @@ | ||
# parseHttpDate | ||
Parses the value of the `Date` header in HTTP responses. | ||
Parses date-times which have the preferred format [as defined by HTTP/1.1](https://tools.ietf.org/html/rfc7231#section-7.1.1.1). An example of such a date-time is: | ||
## Description | ||
Parses date-times from HTTP headers such as _Date_, _Last Modified_, and _Expires_. Those date-times almost always have the preferred format [as defined by HTTP/1.1](https://tools.ietf.org/html/rfc7231#section-7.1.1.1). An example of such a date-time is: | ||
> Tue, 15 Nov 1994 08:12:31 GMT | ||
This format is used in HTTP headers such as _Date_, _Last-Modified_, and _Expires_. It is a subset of the specification used by the [Internet Message Format](https://tools.ietf.org/html/rfc5322). Note that the HTTP/1.1 specification also defines two obsolete formats, which this implementation does not support. | ||
This format is a subset of the specification used by the [Internet Message Format](https://tools.ietf.org/html/rfc5322). | ||
## Usage | ||
# Installation | ||
Install `parsehttpdate` using npm or Yarn and import the function: | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
import parseHttpDate from 'parseHttpDate'; | ||
``` | ||
Alternatively, include `parsehttpdate` through unpkg: | ||
```html | ||
<script src="https://unpkg.com/parsehttpdate@^1.0.2"></script> | ||
``` | ||
This alternative makes the function available at `window.parseHttpDate`. | ||
# Usage | ||
```javascript | ||
parseHttpDate('Wed, 21 Oct 2015 07:28:00 GMT'); | ||
@@ -22,4 +35,2 @@ ``` | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
fetch('/') | ||
@@ -42,4 +53,2 @@ .then(({headers}) => { | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
async function getServerDate() { | ||
@@ -65,8 +74,6 @@ const {headers} = await fetch('/'); | ||
```javascript | ||
import parseHttpDate from 'parsehttpdate'; | ||
parseHttpDate('Wed, 21 Oct 2015 07:28:00 GMT', false); | ||
``` | ||
## ISO 8601 timestamps | ||
## Other formats | ||
@@ -77,3 +84,3 @@ Does your date-time look nothing like the example above, but rather something like this? | ||
Congratulations: your date-time is formatted [according to ISO 8601](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15). _You don't need parseHttpDate_. You don't need any library. | ||
Congratulations: your date-time is formatted [according to ISO 8601](http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15). _You don't need parseHttpDate_. You don't need any library: | ||
@@ -84,5 +91,13 @@ ```javascript | ||
## License (X11/MIT) | ||
Copyright (c) 2018 Pimm "de Chinchilla" Hogeling | ||
The HTTP/1.1 specification defines two obsolete formats besides the preferred format of the examples above: | ||
> Sunday, 06-Nov-94 08:49:37 GMT | ||
> Sun Nov 6 08:49:37 1994 | ||
This implementation does not support those. | ||
# License (X11/MIT) | ||
Copyright (c) 2018-2019 Pimm "de Chinchilla" Hogeling | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
@@ -92,2 +107,2 @@ | ||
**The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** | ||
**The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.** |
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
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
14525
10
0
1
102
6
62