Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-enum-util

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-enum-util - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

4

dist/commonjs/EnumWrapper.js

@@ -7,3 +7,3 @@ "use strict";

this.enumObj = enumObj;
this.keysList = Object.freeze(objectKeysUtil_1.getOwnEnumerableNonArrayIndexKeys(enumObj));
this.keysList = Object.freeze(objectKeysUtil_1.getOwnEnumerableNonNumericKeys(enumObj));
var length = this.keysList.length;

@@ -130,3 +130,3 @@ var valuesList = new Array(length);

return (key != null &&
objectKeysUtil_1.isNonArrayIndexKey(key) &&
objectKeysUtil_1.isNonNumericKey(key) &&
this.enumObj.hasOwnProperty(key));

@@ -133,0 +133,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function isNonArrayIndexKey(key) {
var parsedInt = parseInt(key, 10);
if (parsedInt < 0 || parsedInt >= 4294967295) {
return true;
}
return key !== String(parsedInt);
function isNonNumericKey(key) {
return key !== String(parseFloat(key));
}
exports.isNonArrayIndexKey = isNonArrayIndexKey;
function getOwnEnumerableNonArrayIndexKeysES6(obj) {
exports.isNonNumericKey = isNonNumericKey;
function getOwnEnumerableNonNumericKeysES6(obj) {
return Object.getOwnPropertyNames(obj).filter(function (key) {
return obj.propertyIsEnumerable(key) && isNonArrayIndexKey(key);
return obj.propertyIsEnumerable(key) && isNonNumericKey(key);
});
}
exports.getOwnEnumerableNonArrayIndexKeysES6 = getOwnEnumerableNonArrayIndexKeysES6;
function getOwnEnumerableNonArrayIndexKeysES5(obj) {
return Object.keys(obj).filter(isNonArrayIndexKey);
exports.getOwnEnumerableNonNumericKeysES6 = getOwnEnumerableNonNumericKeysES6;
function getOwnEnumerableNonNumericKeysES5(obj) {
return Object.keys(obj).filter(isNonNumericKey);
}
exports.getOwnEnumerableNonArrayIndexKeysES5 = getOwnEnumerableNonArrayIndexKeysES5;
function getOwnEnumerableNonArrayIndexKeysES3(obj) {
exports.getOwnEnumerableNonNumericKeysES5 = getOwnEnumerableNonNumericKeysES5;
function getOwnEnumerableNonNumericKeysES3(obj) {
var result = [];

@@ -26,3 +22,3 @@ for (var key in obj) {

obj.propertyIsEnumerable(key) &&
isNonArrayIndexKey(key)) {
isNonNumericKey(key)) {
result.push(key);

@@ -33,8 +29,8 @@ }

}
exports.getOwnEnumerableNonArrayIndexKeysES3 = getOwnEnumerableNonArrayIndexKeysES3;
exports.getOwnEnumerableNonArrayIndexKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonArrayIndexKeysES6
exports.getOwnEnumerableNonNumericKeysES3 = getOwnEnumerableNonNumericKeysES3;
exports.getOwnEnumerableNonNumericKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonNumericKeysES6
: Object.keys
? getOwnEnumerableNonArrayIndexKeysES5
: getOwnEnumerableNonArrayIndexKeysES3;
? getOwnEnumerableNonNumericKeysES5
: getOwnEnumerableNonNumericKeysES3;
//# sourceMappingURL=objectKeysUtil.js.map

@@ -1,6 +0,6 @@

import { isNonArrayIndexKey, getOwnEnumerableNonArrayIndexKeys } from "./objectKeysUtil";
import { isNonNumericKey, getOwnEnumerableNonNumericKeys } from "./objectKeysUtil";
var EnumWrapper = (function () {
function EnumWrapper(enumObj) {
this.enumObj = enumObj;
this.keysList = Object.freeze(getOwnEnumerableNonArrayIndexKeys(enumObj));
this.keysList = Object.freeze(getOwnEnumerableNonNumericKeys(enumObj));
var length = this.keysList.length;

@@ -127,3 +127,3 @@ var valuesList = new Array(length);

return (key != null &&
isNonArrayIndexKey(key) &&
isNonNumericKey(key) &&
this.enumObj.hasOwnProperty(key));

@@ -130,0 +130,0 @@ };

@@ -1,17 +0,13 @@

export function isNonArrayIndexKey(key) {
var parsedInt = parseInt(key, 10);
if (parsedInt < 0 || parsedInt >= 4294967295) {
return true;
}
return key !== String(parsedInt);
export function isNonNumericKey(key) {
return key !== String(parseFloat(key));
}
export function getOwnEnumerableNonArrayIndexKeysES6(obj) {
export function getOwnEnumerableNonNumericKeysES6(obj) {
return Object.getOwnPropertyNames(obj).filter(function (key) {
return obj.propertyIsEnumerable(key) && isNonArrayIndexKey(key);
return obj.propertyIsEnumerable(key) && isNonNumericKey(key);
});
}
export function getOwnEnumerableNonArrayIndexKeysES5(obj) {
return Object.keys(obj).filter(isNonArrayIndexKey);
export function getOwnEnumerableNonNumericKeysES5(obj) {
return Object.keys(obj).filter(isNonNumericKey);
}
export function getOwnEnumerableNonArrayIndexKeysES3(obj) {
export function getOwnEnumerableNonNumericKeysES3(obj) {
var result = [];

@@ -21,3 +17,3 @@ for (var key in obj) {

obj.propertyIsEnumerable(key) &&
isNonArrayIndexKey(key)) {
isNonNumericKey(key)) {
result.push(key);

@@ -28,7 +24,7 @@ }

}
export var getOwnEnumerableNonArrayIndexKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonArrayIndexKeysES6
export var getOwnEnumerableNonNumericKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonNumericKeysES6
: Object.keys
? getOwnEnumerableNonArrayIndexKeysES5
: getOwnEnumerableNonArrayIndexKeysES3;
? getOwnEnumerableNonNumericKeysES5
: getOwnEnumerableNonNumericKeysES3;
//# sourceMappingURL=objectKeysUtil.js.map
import { StringKeyOf } from "./types";
/**
* Return true if the specified object key value is NOT an array index key.
* Return true if the specified object key value is NOT a numeric key.
* @param key - An object key.
* @return true if the specified object key value is NOT an array index key.
* @return true if the specified object key value is NOT a numeric key.
*/
export declare function isNonArrayIndexKey(key: string): boolean;
export declare function isNonNumericKey(key: string): boolean;
/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES6.

@@ -16,7 +16,7 @@ * The order of the result is *guaranteed* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export declare function getOwnEnumerableNonArrayIndexKeysES6<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
export declare function getOwnEnumerableNonNumericKeysES6<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES5.

@@ -27,7 +27,7 @@ * The order of the result is *most likely* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export declare function getOwnEnumerableNonArrayIndexKeysES5<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
export declare function getOwnEnumerableNonNumericKeysES5<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES3.

@@ -38,7 +38,7 @@ * The order of the result is *most likely* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export declare function getOwnEnumerableNonArrayIndexKeysES3<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
export declare function getOwnEnumerableNonNumericKeysES3<T extends Record<string, any>>(obj: T): StringKeyOf<T>[];
/**
* Get all own enumerable string (non-array-index) keys of an object, using
* Get all own enumerable string (non-numeric) keys of an object, using
* the best implementation available.

@@ -52,5 +52,5 @@ * The order of the result is either *guaranteed* or *most likely* to be in the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export declare const getOwnEnumerableNonArrayIndexKeys: typeof getOwnEnumerableNonArrayIndexKeysES6;
export declare const getOwnEnumerableNonNumericKeys: typeof getOwnEnumerableNonNumericKeysES6;
//# sourceMappingURL=objectKeysUtil.d.ts.map
{
"name": "ts-enum-util",
"version": "4.0.0",
"version": "4.0.1",
"description": "TypeScript Enum Utilities",

@@ -5,0 +5,0 @@ "repository": {

import { StringKeyOf } from "./types";
import {
isNonArrayIndexKey,
getOwnEnumerableNonArrayIndexKeys
isNonNumericKey,
getOwnEnumerableNonNumericKeys
} from "./objectKeysUtil";

@@ -67,8 +67,6 @@

public constructor(private readonly enumObj: T) {
// Include only own enumerable keys that are not array indexes.
// Include only own enumerable keys that are not numeric.
// This is necessary to ignore the reverse-lookup entries that are automatically added
// by TypeScript to numeric enums.
this.keysList = Object.freeze(
getOwnEnumerableNonArrayIndexKeys(enumObj)
);
this.keysList = Object.freeze(getOwnEnumerableNonNumericKeys(enumObj));

@@ -321,3 +319,3 @@ const length = this.keysList.length;

key != null &&
isNonArrayIndexKey(key) &&
isNonNumericKey(key) &&
this.enumObj.hasOwnProperty(key)

@@ -324,0 +322,0 @@ );

import { StringKeyOf } from "./types";
/**
* Return true if the specified object key value is NOT an array index key.
* Return true if the specified object key value is NOT a numeric key.
* @param key - An object key.
* @return true if the specified object key value is NOT an array index key.
* @return true if the specified object key value is NOT a numeric key.
*/
export function isNonArrayIndexKey(key: string): boolean {
// See ECMAScript spec section 15.4 for definition of an array index:
// http://www.ecma-international.org/ecma-262/5.1/#sec-15.4
// Parse the key as an integer
const parsedInt = parseInt(key, 10);
// If the parsed value is outside of the range of valid values,
// then it clearly can't be a valid array index.
// NOTE: Maximum unsigned 32-bit integer = 2^32-1 = 4294967295
if (parsedInt < 0 || parsedInt >= 4294967295) {
return true;
}
// The parsed value is within the valid range, but the original key is not
// a valid array index if it is not equal to the string representation of
// the parsed numeric value.
return key !== String(parsedInt);
export function isNonNumericKey(key: string): boolean {
return key !== String(parseFloat(key));
}
/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES6.

@@ -36,9 +20,9 @@ * The order of the result is *guaranteed* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export function getOwnEnumerableNonArrayIndexKeysES6<
export function getOwnEnumerableNonNumericKeysES6<
T extends Record<string, any>
>(obj: T): StringKeyOf<T>[] {
return Object.getOwnPropertyNames(obj).filter((key) => {
return obj.propertyIsEnumerable(key) && isNonArrayIndexKey(key);
return obj.propertyIsEnumerable(key) && isNonNumericKey(key);
}) as StringKeyOf<T>[];

@@ -48,3 +32,3 @@ }

/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES5.

@@ -55,12 +39,12 @@ * The order of the result is *most likely* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export function getOwnEnumerableNonArrayIndexKeysES5<
export function getOwnEnumerableNonNumericKeysES5<
T extends Record<string, any>
>(obj: T): StringKeyOf<T>[] {
return Object.keys(obj).filter(isNonArrayIndexKey) as StringKeyOf<T>[];
return Object.keys(obj).filter(isNonNumericKey) as StringKeyOf<T>[];
}
/**
* Get all own enumerable string (non-array-index) keys of an object.
* Get all own enumerable string (non-numeric) keys of an object.
* Implemented in terms of methods available in ES3.

@@ -71,5 +55,5 @@ * The order of the result is *most likely* to be in the same order in which the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export function getOwnEnumerableNonArrayIndexKeysES3<
export function getOwnEnumerableNonNumericKeysES3<
T extends Record<string, any>

@@ -83,3 +67,3 @@ >(obj: T): StringKeyOf<T>[] {

obj.propertyIsEnumerable(key) &&
isNonArrayIndexKey(key)
isNonNumericKey(key)
) {

@@ -94,3 +78,3 @@ result.push(key);

/**
* Get all own enumerable string (non-array-index) keys of an object, using
* Get all own enumerable string (non-numeric) keys of an object, using
* the best implementation available.

@@ -104,8 +88,8 @@ * The order of the result is either *guaranteed* or *most likely* to be in the

* @param obj - An object.
* @return A list of all the object's own enumerable string (non-array-index) keys.
* @return A list of all the object's own enumerable string (non-numeric) keys.
*/
export const getOwnEnumerableNonArrayIndexKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonArrayIndexKeysES6
export const getOwnEnumerableNonNumericKeys = Object.getOwnPropertyNames
? getOwnEnumerableNonNumericKeysES6
: Object.keys
? getOwnEnumerableNonArrayIndexKeysES5
: getOwnEnumerableNonArrayIndexKeysES3;
? getOwnEnumerableNonNumericKeysES5
: getOwnEnumerableNonNumericKeysES3;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc