@bevry/ecmascript-versions
Advanced tools
Comparing version 2.0.1 to 3.0.0
@@ -14,3 +14,4 @@ /** | ||
/** | ||
* All the details about an ECMAScript edition/version. | ||
* All the information about an ECMAScript edition/version. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
@@ -22,23 +23,38 @@ export declare type ESVersionInformation = { | ||
}; | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
export declare function getESVersionInformationByVersion(version: ESVersionIdentifier): ESVersionInformation; | ||
/** | ||
* The mapping of an ECMAScript edition number to its information. | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
export declare type ESVersionMap = Map<Number, ESVersionInformation>; | ||
export declare function getESVersionsInformationByVersion(versions: Array<ESVersionIdentifier>): Array<ESVersionInformation>; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export declare function getESVersionsInformation(when?: Date): Array<ESVersionInformation>; | ||
export declare function getESVersionsInformationByDate(when: Date): Array<ESVersionInformation>; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export declare function getESVersions(when?: Date): Array<ESVersionIdentifier>; | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
export declare function getESVersionInformation(when?: Date): ESVersionInformation; | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
export declare function getESVersion(when?: Date): string; | ||
/** Get the ECMAScript version details by the edition number. */ | ||
export declare function getESVersionsByDate(when: Date): Array<ESVersionIdentifier>; | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
export declare function getESVersionInformationByDate(when: Date): ESVersionInformation; | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
export declare function getESVersionByDate(when?: Date): string; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export declare function getESVersionsInformationByNow(): ESVersionInformation[]; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export declare function getESVersionsByNow(): string[]; | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
export declare function getESVersionInformationByNow(): ESVersionInformation; | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
export declare function getESVersionByNow(): string; | ||
/** Get the ECMAScript version information by the edition number. */ | ||
export declare function getESVersionInformationByEdition(edition: Number): ESVersionInformation; | ||
@@ -45,0 +61,0 @@ /** Get the ECMAScript version by the edition number. */ |
@@ -21,5 +21,9 @@ /** | ||
} | ||
const esVersionMap = new Map(); | ||
/** | ||
* ECMAScript version information mapped by the edition number. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByEdition = new Map(); | ||
// June 1997 | ||
esVersionMap.set(1, { | ||
esVersionsByEdition.set(1, { | ||
version: 'ES1', | ||
@@ -30,3 +34,3 @@ ratified: new Date('1997-06-01'), | ||
// June 1998 | ||
esVersionMap.set(2, { | ||
esVersionsByEdition.set(2, { | ||
version: 'ES2', | ||
@@ -37,3 +41,3 @@ ratified: new Date('1998-06-01'), | ||
// December 1999 | ||
esVersionMap.set(3, { | ||
esVersionsByEdition.set(3, { | ||
version: 'ES3', | ||
@@ -45,3 +49,3 @@ ratified: new Date('1999-12-01'), | ||
// December 2009 | ||
esVersionMap.set(5, { | ||
esVersionsByEdition.set(5, { | ||
version: 'ES5', | ||
@@ -54,3 +58,3 @@ ratified: new Date('2009-12-01'), | ||
for (let year = 2015, edition = 6; year <= now.getFullYear(); year++, edition++) { | ||
esVersionMap.set(edition, { | ||
esVersionsByEdition.set(edition, { | ||
version: `ES${year}`, | ||
@@ -61,9 +65,34 @@ ratified: new Date(`${year}-06-01`), | ||
} | ||
// Premake as an array | ||
const esVersionList = Array.from(esVersionMap.values()); | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* ECMAScript version information as an array. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformation(when = now) { | ||
const esVersionList = Array.from(esVersionsByEdition.values()); | ||
/** | ||
* ECMAScript version information mapped by the version identifier. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByVersion = new Map(esVersionList.map((v) => [v.version, v])); | ||
// ------------------------------------ | ||
// By Version | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
export function getESVersionInformationByVersion(version) { | ||
if (esVersionsByVersion.has(version)) | ||
return esVersionsByVersion.get(version); | ||
throw new Error(`ECMAScript version was not found: ${version}`); | ||
} | ||
/** | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByVersion(versions) { | ||
return versions.map((version) => getESVersionInformationByVersion(version)); | ||
} | ||
// ------------------------------------ | ||
// By Date | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByDate(when) { | ||
const time = when.getTime(); | ||
@@ -76,19 +105,45 @@ const results = esVersionList.filter((meta) => time >= meta.ratified.getTime()); | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersions(when = now) { | ||
return getESVersionsInformation(when).map((meta) => meta.version); | ||
export function getESVersionsByDate(when) { | ||
return getESVersionsInformationByDate(when).map((meta) => meta.version); | ||
} | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
export function getESVersionInformation(when = now) { | ||
return getESVersionsInformation(when).slice(-1)[0]; | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
export function getESVersionInformationByDate(when) { | ||
return getESVersionsInformationByDate(when).slice(-1)[0]; | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
export function getESVersion(when = now) { | ||
return getESVersionInformation(when).version; | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
export function getESVersionByDate(when = now) { | ||
return getESVersionInformationByDate(when).version; | ||
} | ||
/** Get the ECMAScript version details by the edition number. */ | ||
// ------------------------------------ | ||
// By Now | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByNow() { | ||
return getESVersionsInformationByDate(now); | ||
} | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsByNow() { | ||
return getESVersionsByDate(now); | ||
} | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionInformationByNow() { | ||
return getESVersionInformationByDate(now); | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionByNow() { | ||
return getESVersionByDate(now); | ||
} | ||
// ------------------------------------ | ||
// By Edition | ||
/** Get the ECMAScript version information by the edition number. */ | ||
export function getESVersionInformationByEdition(edition) { | ||
const meta = esVersionMap.get(edition); | ||
const meta = esVersionsByEdition.get(edition); | ||
if (meta) | ||
@@ -95,0 +150,0 @@ return meta; |
@@ -31,3 +31,4 @@ /** | ||
/** | ||
* All the details about an ECMAScript edition/version. | ||
* All the information about an ECMAScript edition/version. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
@@ -41,11 +42,8 @@ export type ESVersionInformation = { | ||
/** | ||
* The mapping of an ECMAScript edition number to its information. | ||
* ECMAScript version information mapped by the edition number. | ||
* Sorted from oldest first to most recent last. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
export type ESVersionMap = Map<Number, ESVersionInformation> | ||
const esVersionMap: ESVersionMap = new Map() | ||
const esVersionsByEdition: Map<Number, ESVersionInformation> = new Map() | ||
// June 1997 | ||
esVersionMap.set(1, { | ||
esVersionsByEdition.set(1, { | ||
version: 'ES1', | ||
@@ -56,3 +54,3 @@ ratified: new Date('1997-06-01'), | ||
// June 1998 | ||
esVersionMap.set(2, { | ||
esVersionsByEdition.set(2, { | ||
version: 'ES2', | ||
@@ -63,3 +61,3 @@ ratified: new Date('1998-06-01'), | ||
// December 1999 | ||
esVersionMap.set(3, { | ||
esVersionsByEdition.set(3, { | ||
version: 'ES3', | ||
@@ -71,3 +69,3 @@ ratified: new Date('1999-12-01'), | ||
// December 2009 | ||
esVersionMap.set(5, { | ||
esVersionsByEdition.set(5, { | ||
version: 'ES5', | ||
@@ -84,3 +82,3 @@ ratified: new Date('2009-12-01'), | ||
) { | ||
esVersionMap.set(edition, { | ||
esVersionsByEdition.set(edition, { | ||
version: `ES${year}`, | ||
@@ -92,12 +90,46 @@ ratified: new Date(`${year}-06-01`), | ||
// Premake as an array | ||
const esVersionList = Array.from(esVersionMap.values()) | ||
/** | ||
* ECMAScript version information as an array. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionList = Array.from(esVersionsByEdition.values()) | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* ECMAScript version information mapped by the version identifier. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformation( | ||
when: Date = now | ||
const esVersionsByVersion: Map<ESVersionIdentifier, ESVersionInformation> = | ||
new Map(esVersionList.map((v) => [v.version, v])) | ||
// ------------------------------------ | ||
// By Version | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
export function getESVersionInformationByVersion( | ||
version: ESVersionIdentifier | ||
): ESVersionInformation { | ||
if (esVersionsByVersion.has(version)) return esVersionsByVersion.get(version)! | ||
throw new Error(`ECMAScript version was not found: ${version}`) | ||
} | ||
/** | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByVersion( | ||
versions: Array<ESVersionIdentifier> | ||
): Array<ESVersionInformation> { | ||
return versions.map((version) => getESVersionInformationByVersion(version)) | ||
} | ||
// ------------------------------------ | ||
// By Date | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByDate( | ||
when: Date | ||
): Array<ESVersionInformation> { | ||
const time = when.getTime() | ||
@@ -112,26 +144,58 @@ const results = esVersionList.filter( | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersions(when: Date = now): Array<ESVersionIdentifier> { | ||
return getESVersionsInformation(when).map((meta) => meta.version) | ||
export function getESVersionsByDate(when: Date): Array<ESVersionIdentifier> { | ||
return getESVersionsInformationByDate(when).map((meta) => meta.version) | ||
} | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
export function getESVersionInformation( | ||
when: Date = now | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
export function getESVersionInformationByDate( | ||
when: Date | ||
): ESVersionInformation { | ||
return getESVersionsInformation(when).slice(-1)[0] | ||
return getESVersionsInformationByDate(when).slice(-1)[0] | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
export function getESVersion(when: Date = now): string { | ||
return getESVersionInformation(when).version | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
export function getESVersionByDate(when: Date = now): string { | ||
return getESVersionInformationByDate(when).version | ||
} | ||
/** Get the ECMAScript version details by the edition number. */ | ||
// ------------------------------------ | ||
// By Now | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByNow() { | ||
return getESVersionsInformationByDate(now) | ||
} | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsByNow() { | ||
return getESVersionsByDate(now) | ||
} | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionInformationByNow(): ESVersionInformation { | ||
return getESVersionInformationByDate(now) | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionByNow(): string { | ||
return getESVersionByDate(now) | ||
} | ||
// ------------------------------------ | ||
// By Edition | ||
/** Get the ECMAScript version information by the edition number. */ | ||
export function getESVersionInformationByEdition( | ||
edition: Number | ||
): ESVersionInformation { | ||
const meta = esVersionMap.get(edition) | ||
const meta = esVersionsByEdition.get(edition) | ||
if (meta) return meta | ||
@@ -138,0 +202,0 @@ throw new Error(`ECMAScript does not have the edition ${edition}`) |
@@ -21,5 +21,9 @@ /** | ||
} | ||
const esVersionMap = new Map(); | ||
/** | ||
* ECMAScript version information mapped by the edition number. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByEdition = new Map(); | ||
// June 1997 | ||
esVersionMap.set(1, { | ||
esVersionsByEdition.set(1, { | ||
version: 'ES1', | ||
@@ -30,3 +34,3 @@ ratified: new Date('1997-06-01'), | ||
// June 1998 | ||
esVersionMap.set(2, { | ||
esVersionsByEdition.set(2, { | ||
version: 'ES2', | ||
@@ -37,3 +41,3 @@ ratified: new Date('1998-06-01'), | ||
// December 1999 | ||
esVersionMap.set(3, { | ||
esVersionsByEdition.set(3, { | ||
version: 'ES3', | ||
@@ -45,3 +49,3 @@ ratified: new Date('1999-12-01'), | ||
// December 2009 | ||
esVersionMap.set(5, { | ||
esVersionsByEdition.set(5, { | ||
version: 'ES5', | ||
@@ -54,3 +58,3 @@ ratified: new Date('2009-12-01'), | ||
for (let year = 2015, edition = 6; year <= now.getFullYear(); year++, edition++) { | ||
esVersionMap.set(edition, { | ||
esVersionsByEdition.set(edition, { | ||
version: `ES${year}`, | ||
@@ -61,9 +65,34 @@ ratified: new Date(`${year}-06-01`), | ||
} | ||
// Premake as an array | ||
const esVersionList = Array.from(esVersionMap.values()); | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* ECMAScript version information as an array. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformation(when = now) { | ||
const esVersionList = Array.from(esVersionsByEdition.values()); | ||
/** | ||
* ECMAScript version information mapped by the version identifier. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByVersion = new Map(esVersionList.map((v) => [v.version, v])); | ||
// ------------------------------------ | ||
// By Version | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
export function getESVersionInformationByVersion(version) { | ||
if (esVersionsByVersion.has(version)) | ||
return esVersionsByVersion.get(version); | ||
throw new Error(`ECMAScript version was not found: ${version}`); | ||
} | ||
/** | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByVersion(versions) { | ||
return versions.map((version) => getESVersionInformationByVersion(version)); | ||
} | ||
// ------------------------------------ | ||
// By Date | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByDate(when) { | ||
const time = when.getTime(); | ||
@@ -76,19 +105,45 @@ const results = esVersionList.filter((meta) => time >= meta.ratified.getTime()); | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersions(when = now) { | ||
return getESVersionsInformation(when).map((meta) => meta.version); | ||
export function getESVersionsByDate(when) { | ||
return getESVersionsInformationByDate(when).map((meta) => meta.version); | ||
} | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
export function getESVersionInformation(when = now) { | ||
return getESVersionsInformation(when).slice(-1)[0]; | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
export function getESVersionInformationByDate(when) { | ||
return getESVersionsInformationByDate(when).slice(-1)[0]; | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
export function getESVersion(when = now) { | ||
return getESVersionInformation(when).version; | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
export function getESVersionByDate(when = now) { | ||
return getESVersionInformationByDate(when).version; | ||
} | ||
/** Get the ECMAScript version details by the edition number. */ | ||
// ------------------------------------ | ||
// By Now | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByNow() { | ||
return getESVersionsInformationByDate(now); | ||
} | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsByNow() { | ||
return getESVersionsByDate(now); | ||
} | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionInformationByNow() { | ||
return getESVersionInformationByDate(now); | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionByNow() { | ||
return getESVersionByDate(now); | ||
} | ||
// ------------------------------------ | ||
// By Edition | ||
/** Get the ECMAScript version information by the edition number. */ | ||
export function getESVersionInformationByEdition(edition) { | ||
const meta = esVersionMap.get(edition); | ||
const meta = esVersionsByEdition.get(edition); | ||
if (meta) | ||
@@ -95,0 +150,0 @@ return meta; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getESVersionByEdition = exports.getESVersionInformationByEdition = exports.getESVersion = exports.getESVersionInformation = exports.getESVersions = exports.getESVersionsInformation = exports.getDateWithYearOffset = exports.datetime = void 0; | ||
exports.getESVersionByEdition = exports.getESVersionInformationByEdition = exports.getESVersionByNow = exports.getESVersionInformationByNow = exports.getESVersionsByNow = exports.getESVersionsInformationByNow = exports.getESVersionByDate = exports.getESVersionInformationByDate = exports.getESVersionsByDate = exports.getESVersionsInformationByDate = exports.getESVersionsInformationByVersion = exports.getESVersionInformationByVersion = exports.getDateWithYearOffset = exports.datetime = void 0; | ||
/** | ||
@@ -26,5 +26,9 @@ * The datetime to use by default. | ||
exports.getDateWithYearOffset = getDateWithYearOffset; | ||
const esVersionMap = new Map(); | ||
/** | ||
* ECMAScript version information mapped by the edition number. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByEdition = new Map(); | ||
// June 1997 | ||
esVersionMap.set(1, { | ||
esVersionsByEdition.set(1, { | ||
version: 'ES1', | ||
@@ -35,3 +39,3 @@ ratified: new Date('1997-06-01'), | ||
// June 1998 | ||
esVersionMap.set(2, { | ||
esVersionsByEdition.set(2, { | ||
version: 'ES2', | ||
@@ -42,3 +46,3 @@ ratified: new Date('1998-06-01'), | ||
// December 1999 | ||
esVersionMap.set(3, { | ||
esVersionsByEdition.set(3, { | ||
version: 'ES3', | ||
@@ -50,3 +54,3 @@ ratified: new Date('1999-12-01'), | ||
// December 2009 | ||
esVersionMap.set(5, { | ||
esVersionsByEdition.set(5, { | ||
version: 'ES5', | ||
@@ -59,3 +63,3 @@ ratified: new Date('2009-12-01'), | ||
for (let year = 2015, edition = 6; year <= now.getFullYear(); year++, edition++) { | ||
esVersionMap.set(edition, { | ||
esVersionsByEdition.set(edition, { | ||
version: `ES${year}`, | ||
@@ -66,9 +70,36 @@ ratified: new Date(`${year}-06-01`), | ||
} | ||
// Premake as an array | ||
const esVersionList = Array.from(esVersionMap.values()); | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* ECMAScript version information as an array. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersionsInformation(when = now) { | ||
const esVersionList = Array.from(esVersionsByEdition.values()); | ||
/** | ||
* ECMAScript version information mapped by the version identifier. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionsByVersion = new Map(esVersionList.map((v) => [v.version, v])); | ||
// ------------------------------------ | ||
// By Version | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
function getESVersionInformationByVersion(version) { | ||
if (esVersionsByVersion.has(version)) | ||
return esVersionsByVersion.get(version); | ||
throw new Error(`ECMAScript version was not found: ${version}`); | ||
} | ||
exports.getESVersionInformationByVersion = getESVersionInformationByVersion; | ||
/** | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersionsInformationByVersion(versions) { | ||
return versions.map((version) => getESVersionInformationByVersion(version)); | ||
} | ||
exports.getESVersionsInformationByVersion = getESVersionsInformationByVersion; | ||
// ------------------------------------ | ||
// By Date | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersionsInformationByDate(when) { | ||
const time = when.getTime(); | ||
@@ -80,24 +111,54 @@ const results = esVersionList.filter((meta) => time >= meta.ratified.getTime()); | ||
} | ||
exports.getESVersionsInformation = getESVersionsInformation; | ||
exports.getESVersionsInformationByDate = getESVersionsInformationByDate; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersions(when = now) { | ||
return getESVersionsInformation(when).map((meta) => meta.version); | ||
function getESVersionsByDate(when) { | ||
return getESVersionsInformationByDate(when).map((meta) => meta.version); | ||
} | ||
exports.getESVersions = getESVersions; | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
function getESVersionInformation(when = now) { | ||
return getESVersionsInformation(when).slice(-1)[0]; | ||
exports.getESVersionsByDate = getESVersionsByDate; | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
function getESVersionInformationByDate(when) { | ||
return getESVersionsInformationByDate(when).slice(-1)[0]; | ||
} | ||
exports.getESVersionInformation = getESVersionInformation; | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
function getESVersion(when = now) { | ||
return getESVersionInformation(when).version; | ||
exports.getESVersionInformationByDate = getESVersionInformationByDate; | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
function getESVersionByDate(when = now) { | ||
return getESVersionInformationByDate(when).version; | ||
} | ||
exports.getESVersion = getESVersion; | ||
/** Get the ECMAScript version details by the edition number. */ | ||
exports.getESVersionByDate = getESVersionByDate; | ||
// ------------------------------------ | ||
// By Now | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersionsInformationByNow() { | ||
return getESVersionsInformationByDate(now); | ||
} | ||
exports.getESVersionsInformationByNow = getESVersionsInformationByNow; | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
function getESVersionsByNow() { | ||
return getESVersionsByDate(now); | ||
} | ||
exports.getESVersionsByNow = getESVersionsByNow; | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
function getESVersionInformationByNow() { | ||
return getESVersionInformationByDate(now); | ||
} | ||
exports.getESVersionInformationByNow = getESVersionInformationByNow; | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
function getESVersionByNow() { | ||
return getESVersionByDate(now); | ||
} | ||
exports.getESVersionByNow = getESVersionByNow; | ||
// ------------------------------------ | ||
// By Edition | ||
/** Get the ECMAScript version information by the edition number. */ | ||
function getESVersionInformationByEdition(edition) { | ||
const meta = esVersionMap.get(edition); | ||
const meta = esVersionsByEdition.get(edition); | ||
if (meta) | ||
@@ -104,0 +165,0 @@ return meta; |
# History | ||
## v3.0.0 2021 July 27 | ||
- Fetching by what criteria is now explicit | ||
- Added the ability to fetch information by the version identifier | ||
## v2.0.1 2021 July 27 | ||
@@ -4,0 +9,0 @@ |
{ | ||
"name": "@bevry/ecmascript-versions", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "Get all ECMAScript versions, or the ECMAScript version that was ratified on a specific date.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/bevry/es-versions", |
@@ -42,16 +42,23 @@ <!-- TITLE/ --> | ||
import { | ||
getESVersion, | ||
getESVersions, | ||
getDateWithYearOffset, | ||
getESVersionInformationByVersion, | ||
getESVersionByNow, | ||
getESVersionByDate, | ||
getESVersionsByNow, | ||
} from '@bevry/ecmascript-versions' | ||
// results for 2020-11-03 | ||
// get the ratification date for an ECMAScript version | ||
console.log(getESVersionInformationByVersion('ES2020').ratified) // 2020-06-01T00:00:00.000Z | ||
// get the edition number for an ECMAScript version | ||
console.log(getESVersionInformationByVersion('ES2020').edition) // 11 | ||
// get the latest ECMAScript version that was ratified by current date | ||
console.log(getESVersion()) // ES2020 | ||
console.log(getESVersionByNow()) // ES2020 | ||
// get the latest ECMAScript version that was ratified by this time last year | ||
console.log(getESVersion(getDateWithYearOffset(-1))) // ES2019 | ||
console.log(getESVersionByDate(getDateWithYearOffset(-1))) // ES2019 | ||
// get all the latest ECMAScript versions that were ratified so far | ||
console.log(getESVersions()) /* [ | ||
console.log(getESVersionsByNow()) /* [ | ||
'ES1', | ||
@@ -85,3 +92,3 @@ 'ES2', | ||
<script type="module"> | ||
import * as pkg from '//cdn.skypack.dev/@bevry/ecmascript-versions@^2.0.1' | ||
import * as pkg from '//cdn.skypack.dev/@bevry/ecmascript-versions@^3.0.0' | ||
</script> | ||
@@ -94,3 +101,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//unpkg.com/@bevry/ecmascript-versions@^2.0.1' | ||
import * as pkg from '//unpkg.com/@bevry/ecmascript-versions@^3.0.0' | ||
</script> | ||
@@ -103,3 +110,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//dev.jspm.io/@bevry/ecmascript-versions@2.0.1' | ||
import * as pkg from '//dev.jspm.io/@bevry/ecmascript-versions@3.0.0' | ||
</script> | ||
@@ -106,0 +113,0 @@ ``` |
@@ -31,3 +31,4 @@ /** | ||
/** | ||
* All the details about an ECMAScript edition/version. | ||
* All the information about an ECMAScript edition/version. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
@@ -41,11 +42,8 @@ export type ESVersionInformation = { | ||
/** | ||
* The mapping of an ECMAScript edition number to its information. | ||
* ECMAScript version information mapped by the edition number. | ||
* Sorted from oldest first to most recent last. | ||
* https://en.wikipedia.org/wiki/ECMAScript#Versions | ||
*/ | ||
export type ESVersionMap = Map<Number, ESVersionInformation> | ||
const esVersionMap: ESVersionMap = new Map() | ||
const esVersionsByEdition: Map<Number, ESVersionInformation> = new Map() | ||
// June 1997 | ||
esVersionMap.set(1, { | ||
esVersionsByEdition.set(1, { | ||
version: 'ES1', | ||
@@ -56,3 +54,3 @@ ratified: new Date('1997-06-01'), | ||
// June 1998 | ||
esVersionMap.set(2, { | ||
esVersionsByEdition.set(2, { | ||
version: 'ES2', | ||
@@ -63,3 +61,3 @@ ratified: new Date('1998-06-01'), | ||
// December 1999 | ||
esVersionMap.set(3, { | ||
esVersionsByEdition.set(3, { | ||
version: 'ES3', | ||
@@ -71,3 +69,3 @@ ratified: new Date('1999-12-01'), | ||
// December 2009 | ||
esVersionMap.set(5, { | ||
esVersionsByEdition.set(5, { | ||
version: 'ES5', | ||
@@ -84,3 +82,3 @@ ratified: new Date('2009-12-01'), | ||
) { | ||
esVersionMap.set(edition, { | ||
esVersionsByEdition.set(edition, { | ||
version: `ES${year}`, | ||
@@ -92,12 +90,46 @@ ratified: new Date(`${year}-06-01`), | ||
// Premake as an array | ||
const esVersionList = Array.from(esVersionMap.values()) | ||
/** | ||
* ECMAScript version information as an array. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
const esVersionList = Array.from(esVersionsByEdition.values()) | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* ECMAScript version information mapped by the version identifier. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformation( | ||
when: Date = now | ||
const esVersionsByVersion: Map<ESVersionIdentifier, ESVersionInformation> = | ||
new Map(esVersionList.map((v) => [v.version, v])) | ||
// ------------------------------------ | ||
// By Version | ||
/** Get the associated ECMAScript version information for the version identifier. */ | ||
export function getESVersionInformationByVersion( | ||
version: ESVersionIdentifier | ||
): ESVersionInformation { | ||
if (esVersionsByVersion.has(version)) return esVersionsByVersion.get(version)! | ||
throw new Error(`ECMAScript version was not found: ${version}`) | ||
} | ||
/** | ||
* Get all the associated ECMAScript version information for the version identifiers. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByVersion( | ||
versions: Array<ESVersionIdentifier> | ||
): Array<ESVersionInformation> { | ||
return versions.map((version) => getESVersionInformationByVersion(version)) | ||
} | ||
// ------------------------------------ | ||
// By Date | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByDate( | ||
when: Date | ||
): Array<ESVersionInformation> { | ||
const time = when.getTime() | ||
@@ -112,26 +144,58 @@ const results = esVersionList.filter( | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the datetime. | ||
* Get all the ECMAScript versions that have been ratified by the specified datetime. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersions(when: Date = now): Array<ESVersionIdentifier> { | ||
return getESVersionsInformation(when).map((meta) => meta.version) | ||
export function getESVersionsByDate(when: Date): Array<ESVersionIdentifier> { | ||
return getESVersionsInformationByDate(when).map((meta) => meta.version) | ||
} | ||
/** Get the latest ECMAScript version details that was the ratified by the datetime. */ | ||
export function getESVersionInformation( | ||
when: Date = now | ||
/** Get the latest ECMAScript version information that was the ratified by the specified datetime. */ | ||
export function getESVersionInformationByDate( | ||
when: Date | ||
): ESVersionInformation { | ||
return getESVersionsInformation(when).slice(-1)[0] | ||
return getESVersionsInformationByDate(when).slice(-1)[0] | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the datetime. */ | ||
export function getESVersion(when: Date = now): string { | ||
return getESVersionInformation(when).version | ||
/** Get the latest ECMAScript version that has been ratified by the specified datetime. */ | ||
export function getESVersionByDate(when: Date = now): string { | ||
return getESVersionInformationByDate(when).version | ||
} | ||
/** Get the ECMAScript version details by the edition number. */ | ||
// ------------------------------------ | ||
// By Now | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsInformationByNow() { | ||
return getESVersionsInformationByDate(now) | ||
} | ||
/** | ||
* Get all the ECMAScript versions that have been ratified by the current datetime, or {@link datetime}. | ||
* Sorted from oldest first to most recent last. | ||
*/ | ||
export function getESVersionsByNow() { | ||
return getESVersionsByDate(now) | ||
} | ||
/** Get the latest ECMAScript version information that was the ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionInformationByNow(): ESVersionInformation { | ||
return getESVersionInformationByDate(now) | ||
} | ||
/** Get the latest ECMAScript version that has been ratified by the current datetime, or {@link datetime}. */ | ||
export function getESVersionByNow(): string { | ||
return getESVersionByDate(now) | ||
} | ||
// ------------------------------------ | ||
// By Edition | ||
/** Get the ECMAScript version information by the edition number. */ | ||
export function getESVersionInformationByEdition( | ||
edition: Number | ||
): ESVersionInformation { | ||
const meta = esVersionMap.get(edition) | ||
const meta = esVersionsByEdition.get(edition) | ||
if (meta) return meta | ||
@@ -138,0 +202,0 @@ throw new Error(`ECMAScript does not have the edition ${edition}`) |
Sorry, the diff of this file is not supported yet
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
55013
9
892
193