@azure/core-util
Advanced tools
Comparing version 1.0.1-alpha.20220523.1 to 1.0.1-alpha.20220815.2
@@ -9,2 +9,3 @@ // Copyright (c) Microsoft Corporation. | ||
export { computeSha256Hash, computeSha256Hmac } from "./sha256"; | ||
export { isDefined, isObjectWithProperties, objectHasProperty } from "./typeGuards"; | ||
//# sourceMappingURL=index.js.map |
@@ -121,2 +121,36 @@ 'use strict'; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* Helper TypeGuard that checks if something is defined or not. | ||
* @param thing - Anything | ||
*/ | ||
function isDefined(thing) { | ||
return typeof thing !== "undefined" && thing !== null; | ||
} | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified properties. | ||
* @param thing - Anything. | ||
* @param properties - The name of the properties that should appear in the object. | ||
*/ | ||
function isObjectWithProperties(thing, properties) { | ||
if (!isDefined(thing) || typeof thing !== "object") { | ||
return false; | ||
} | ||
for (const property of properties) { | ||
if (!objectHasProperty(thing, property)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified property. | ||
* @param thing - Any object. | ||
* @param property - The name of the property that should appear in the object. | ||
*/ | ||
function objectHasProperty(thing, property) { | ||
return (isDefined(thing) && typeof thing === "object" && property in thing); | ||
} | ||
exports.computeSha256Hash = computeSha256Hash; | ||
@@ -127,5 +161,8 @@ exports.computeSha256Hmac = computeSha256Hmac; | ||
exports.getRandomIntegerInclusive = getRandomIntegerInclusive; | ||
exports.isDefined = isDefined; | ||
exports.isError = isError; | ||
exports.isNode = isNode; | ||
exports.isObject = isObject; | ||
exports.isObjectWithProperties = isObjectWithProperties; | ||
exports.objectHasProperty = objectHasProperty; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@azure/core-util", | ||
"version": "1.0.1-alpha.20220523.1", | ||
"version": "1.0.1-alpha.20220815.2", | ||
"description": "Core library for shared utility methods", | ||
@@ -5,0 +5,0 @@ "sdk-type": "client", |
@@ -37,2 +37,7 @@ /** | ||
/** | ||
* Helper TypeGuard that checks if something is defined or not. | ||
* @param thing - Anything | ||
*/ | ||
export declare function isDefined<T>(thing: T | undefined | null): thing is T; | ||
/** | ||
* Typeguard for an error object shape (has name and message) | ||
@@ -52,2 +57,14 @@ * @param e - Something caught by a catch clause. | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified properties. | ||
* @param thing - Anything. | ||
* @param properties - The name of the properties that should appear in the object. | ||
*/ | ||
export declare function isObjectWithProperties<Thing, PropertyName extends string>(thing: Thing, properties: PropertyName[]): thing is Thing & Record<PropertyName, unknown>; | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified property. | ||
* @param thing - Any object. | ||
* @param property - The name of the property that should appear in the object. | ||
*/ | ||
export declare function objectHasProperty<Thing, PropertyName extends string>(thing: Thing, property: PropertyName): thing is Thing & Record<PropertyName, unknown>; | ||
/** | ||
* A generic shape for a plain JS object. | ||
@@ -54,0 +71,0 @@ */ |
@@ -42,2 +42,8 @@ /** | ||
/** | ||
* Helper TypeGuard that checks if something is defined or not. | ||
* @param thing - Anything | ||
*/ | ||
export declare function isDefined<T>(thing: T | undefined | null): thing is T; | ||
/** | ||
* Typeguard for an error object shape (has name and message) | ||
@@ -60,2 +66,16 @@ * @param e - Something caught by a catch clause. | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified properties. | ||
* @param thing - Anything. | ||
* @param properties - The name of the properties that should appear in the object. | ||
*/ | ||
export declare function isObjectWithProperties<Thing, PropertyName extends string>(thing: Thing, properties: PropertyName[]): thing is Thing & Record<PropertyName, unknown>; | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified property. | ||
* @param thing - Any object. | ||
* @param property - The name of the property that should appear in the object. | ||
*/ | ||
export declare function objectHasProperty<Thing, PropertyName extends string>(thing: Thing, property: PropertyName): thing is Thing & Record<PropertyName, unknown>; | ||
/** | ||
* A generic shape for a plain JS object. | ||
@@ -62,0 +82,0 @@ */ |
Sorry, the diff of this file is not supported yet
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
59431
33
601