@travetto/base
Advanced tools
Comparing version 3.0.0-rc.19 to 3.0.0-rc.20
{ | ||
"name": "@travetto/base", | ||
"version": "3.0.0-rc.19", | ||
"version": "3.0.0-rc.20", | ||
"description": "Environment config and common utilities for travetto applications.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import { ObjectUtil } from './object'; | ||
import { Class, ClassInstance } from './types'; | ||
import { Class, ClassInstance, TypedObject } from './types'; | ||
@@ -186,2 +186,29 @@ const REGEX_PAT = /[\/](.*)[\/](i|g|m|s)?/; | ||
} | ||
/** | ||
* Filter object by excluding specific keys | ||
* @param obj A value to filter, primitives will be untouched | ||
* @param exclude Strings or patterns to exclude against | ||
* @returns | ||
*/ | ||
static filterByKeys<T>(obj: T, exclude: (string | RegExp)[]): T { | ||
if (obj !== null && obj !== undefined && typeof obj === 'object') { | ||
const out: Partial<T> = {}; | ||
for (const key of TypedObject.keys(obj)) { | ||
if (!exclude.some(r => typeof key === 'string' && (typeof r === 'string' ? r === key : r.test(key)))) { | ||
const val = obj[key]; | ||
if (typeof val === 'object') { | ||
out[key] = this.filterByKeys(val, exclude); | ||
} else { | ||
out[key] = val; | ||
} | ||
} | ||
} | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
return out as T; | ||
} else { | ||
return obj; | ||
} | ||
} | ||
} |
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
88741
2173