@cedx/enum
Advanced tools
Comparing version 6.1.0 to 6.1.1
@@ -39,13 +39,12 @@ (function (exports) { | ||
static create(typeDef) { | ||
const descriptor = { configurable: false, enumerable: false, writable: false }; | ||
const enumType = {}; | ||
Reflect.defineProperty(enumType, isEnum, { ...descriptor, value: true }); | ||
Reflect.defineProperty(enumType, isEnum, { value: true }); | ||
const scalarTypes = ['boolean', 'number', 'string']; | ||
for (const [name, value] of Object.entries(typeDef)) | ||
if (scalarTypes.includes(typeof value)) | ||
Reflect.defineProperty(enumType, name, { ...descriptor, enumerable: true, value }); | ||
Reflect.defineProperty(enumType, name, { enumerable: true, value }); | ||
const methods = ['assert', 'coerce', 'entries', 'getIndex', 'getName', 'isDefined', 'names', 'values']; | ||
for (const name of methods) { | ||
const method = Reflect.get(Enum, name).bind(enumType, enumType); | ||
Reflect.defineProperty(enumType, name, { ...descriptor, value: method }); | ||
Reflect.defineProperty(enumType, name, { value: method }); | ||
} | ||
@@ -52,0 +51,0 @@ return Object.freeze(enumType); |
@@ -1,1 +0,1 @@ | ||
(function(a){'use strict';const b=Symbol("Enum");class c{static assert(a,b){if(c.isDefined(a,b))return b;throw new TypeError(`Invalid enumerated value: ${b}`)}static coerce(a,b,d){return c.isDefined(a,b)?b:d}static create(a){const d={configurable:!1,enumerable:!1,writable:!1},e={};Reflect.defineProperty(e,b,{...d,value:!0});const f=["boolean","number","string"];for(const[b,c]of Object.entries(a))f.includes(typeof c)&&Reflect.defineProperty(e,b,{...d,enumerable:!0,value:c});const g=["assert","coerce","entries","getIndex","getName","isDefined","names","values"];for(const b of g){const a=Reflect.get(c,b).bind(e,e);Reflect.defineProperty(e,b,{...d,value:a})}return Object.freeze(e)}static entries(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.entries(a):c.names(a).map(b=>[b,Reflect.get(a,b)])}static getIndex(a,b){return c.values(a).indexOf(b)}static getName(a,b){const d=c.getIndex(a,b);return 0<=d?c.names(a)[d]:""}static isDefined(a,b){return c.values(a).includes(b)}static names(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.keys(a):Object.values(a).filter(a=>"string"==typeof a)}static values(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.values(a):Object.values(a).filter(a=>"number"==typeof a)}static _hasEnumSymbol(a){return Reflect.has(a,b)&&!0===Reflect.get(a,b)}static _isStringEnum(a){return Object.values(a).every(a=>"string"==typeof a)}}a.Enum=c})(this.window=this.window||{}); | ||
(function(a){'use strict';const b=Symbol("Enum");class c{static assert(a,b){if(c.isDefined(a,b))return b;throw new TypeError(`Invalid enumerated value: ${b}`)}static coerce(a,b,d){return c.isDefined(a,b)?b:d}static create(a){const d={};Reflect.defineProperty(d,b,{value:!0});const e=["boolean","number","string"];for(const[b,c]of Object.entries(a))e.includes(typeof c)&&Reflect.defineProperty(d,b,{enumerable:!0,value:c});const f=["assert","coerce","entries","getIndex","getName","isDefined","names","values"];for(const b of f){const a=Reflect.get(c,b).bind(d,d);Reflect.defineProperty(d,b,{value:a})}return Object.freeze(d)}static entries(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.entries(a):c.names(a).map(b=>[b,Reflect.get(a,b)])}static getIndex(a,b){return c.values(a).indexOf(b)}static getName(a,b){const d=c.getIndex(a,b);return 0<=d?c.names(a)[d]:""}static isDefined(a,b){return c.values(a).includes(b)}static names(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.keys(a):Object.values(a).filter(a=>"string"==typeof a)}static values(a){return c._hasEnumSymbol(a)||c._isStringEnum(a)?Object.values(a):Object.values(a).filter(a=>"number"==typeof a)}static _hasEnumSymbol(a){return Reflect.has(a,b)&&!0===Reflect.get(a,b)}static _isStringEnum(a){return Object.values(a).every(a=>"string"==typeof a)}}a.Enum=c})(this.window=this.window||{}); |
# Changelog | ||
## Version [6.1.1](https://github.com/cedx/enum.js/compare/v6.1.0...v6.1.1) | ||
- Fixed the [issue #4](https://github.com/cedx/enum.js/issues/4): [Microsoft Edge](https://www.microsoft.com/en-us/windows/microsoft-edge) does not support object spread properties. | ||
## Version [6.1.0](https://github.com/cedx/enum.js/compare/v6.0.0...v6.1.0) | ||
@@ -4,0 +7,0 @@ - Added support for [TypeScript enums](https://www.typescriptlang.org/docs/handbook/enums.html). |
@@ -8,3 +8,3 @@ # Installation | ||
!!! warning | ||
Enums for JS requires Node.js >= **12.7.0**. | ||
Enums for JS requires Node.js >= **12.8.0**. | ||
@@ -15,6 +15,6 @@ You can verify if you're already good to go with the following commands: | ||
node --version | ||
# v12.7.0 | ||
# v12.8.0 | ||
npm --version | ||
# 6.10.0 | ||
# 6.10.2 | ||
``` | ||
@@ -21,0 +21,0 @@ |
@@ -36,13 +36,12 @@ /** A symbol indicating that an object is an enumeration. */ | ||
static create(typeDef) { | ||
const descriptor = { configurable: false, enumerable: false, writable: false }; | ||
const enumType = {}; | ||
Reflect.defineProperty(enumType, isEnum, { ...descriptor, value: true }); | ||
Reflect.defineProperty(enumType, isEnum, { value: true }); | ||
const scalarTypes = ['boolean', 'number', 'string']; | ||
for (const [name, value] of Object.entries(typeDef)) | ||
if (scalarTypes.includes(typeof value)) | ||
Reflect.defineProperty(enumType, name, { ...descriptor, enumerable: true, value }); | ||
Reflect.defineProperty(enumType, name, { enumerable: true, value }); | ||
const methods = ['assert', 'coerce', 'entries', 'getIndex', 'getName', 'isDefined', 'names', 'values']; | ||
for (const name of methods) { | ||
const method = Reflect.get(Enum, name).bind(enumType, enumType); | ||
Reflect.defineProperty(enumType, name, { ...descriptor, value: method }); | ||
Reflect.defineProperty(enumType, name, { value: method }); | ||
} | ||
@@ -49,0 +48,0 @@ return Object.freeze(enumType); |
@@ -11,3 +11,3 @@ { | ||
"types": "lib/index.d.ts", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"author": { | ||
@@ -35,3 +35,3 @@ "email": "cedric@belin.io", | ||
"nyc": "^14.1.1", | ||
"rollup": "^1.18.0", | ||
"rollup": "^1.19.3", | ||
"source-map-support": "^0.5.13", | ||
@@ -43,3 +43,3 @@ "ts-node": "^8.3.0", | ||
"engines": { | ||
"node": ">=12.7.0", | ||
"node": ">=12.8.0", | ||
"npm": ">=6.10.0" | ||
@@ -46,0 +46,0 @@ }, |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
50416
449