Skip to content

Commit

Permalink
Minor formatting changes and removed type defs from coverage calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Jul 9, 2023
1 parent a233276 commit b6db3c8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 135 deletions.
1 change: 1 addition & 0 deletions packages/common/.c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
],
"exclude": [
"__tests__/src/main.js",
"__tests__/src/types.js",
"__tests__/types/**"
],
"reporter": [
Expand Down
36 changes: 18 additions & 18 deletions packages/common/src/type-utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
/**
* isDefined
*
* Utility function to check if a variable is neither null nor undefined.
* This function helps in making TypeScript infer the type of the variable
* as being defined, excluding `null` and `undefined`.
*
* The function uses strict equality (`!==`) for the comparison, ensuring
* that the variable is not just falsy (like an empty string or zero),
* but is truly either `null` or `undefined`.
*
* @param arg - The variable to be checked
* @returns true if the variable is neither `null` nor `undefined`
*/
export function isDefined<T>(arg: T): arg is Exclude<T, null | undefined> {
return arg !== null && typeof arg !== 'undefined';
}

/**
* isArrayBufferSlice
*
Expand All @@ -35,6 +17,24 @@ export function isArrayBufferSlice(arrayBufferView: ArrayBufferView): boolean {
return arrayBufferView.byteOffset !== 0 || arrayBufferView.byteLength !== arrayBufferView.buffer.byteLength;
}

/**
* isDefined
*
* Utility function to check if a variable is neither null nor undefined.
* This function helps in making TypeScript infer the type of the variable
* as being defined, excluding `null` and `undefined`.
*
* The function uses strict equality (`!==`) for the comparison, ensuring
* that the variable is not just falsy (like an empty string or zero),
* but is truly either `null` or `undefined`.
*
* @param arg - The variable to be checked
* @returns true if the variable is neither `null` nor `undefined`
*/
export function isDefined<T>(arg: T): arg is Exclude<T, null | undefined> {
return arg !== null && typeof arg !== 'undefined';
}

/**
* universalTypeOf
*
Expand Down
58 changes: 29 additions & 29 deletions packages/crypto/src/utils-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@ import type { BufferKeyPair, ManagedKey, ManagedKeyPair, Web5Crypto } from './ty
import { universalTypeOf } from '@tbd54566975/common';
import { bytesToHex, randomBytes } from '@noble/hashes/utils';

/**
* Checks whether the properties object provided contains the specified property.
*
* @param property Property key to check for.
* @param properties Properties object to check within.
* @returns void
* @throws {SyntaxError} If the property is not a key in the properties object.
*/
export function checkRequiredProperty(options: {
property: string,
inObject: object
}): void {
if (!options || options.property === undefined || options.inObject === undefined) {
throw new TypeError(`One or more required arguments missing: 'property, properties'`);
}
const { property, inObject } = options;
if (!(property in inObject)) {
throw new TypeError(`Required parameter was missing: '${property}'`);
}
}

/**
* Checks whether the property specified is a member of the list of valid properties.
*
Expand All @@ -29,24 +50,16 @@ export function checkValidProperty(options: {
}

/**
* Checks whether the properties object provided contains the specified property.
* Type guard function to check if the given key is a raw key pair
* of ArrayBuffers.
*
* @param property Property key to check for.
* @param properties Properties object to check within.
* @returns void
* @throws {SyntaxError} If the property is not a key in the properties object.
* @param key The key to check.
* @returns True if the key is a pair of key ArrayBuffers, false otherwise.
*/
export function checkRequiredProperty(options: {
property: string,
inObject: object
}): void {
if (!options || options.property === undefined || options.inObject === undefined) {
throw new TypeError(`One or more required arguments missing: 'property, properties'`);
}
const { property, inObject } = options;
if (!(property in inObject)) {
throw new TypeError(`Required parameter was missing: '${property}'`);
}
export function isBufferKeyPair(key: BufferKeyPair | undefined): key is BufferKeyPair {
return (key && 'privateKey' in key && 'publicKey' in key &&
universalTypeOf(key.privateKey) === 'ArrayBuffer' &&
universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false;
}

/**
Expand Down Expand Up @@ -80,19 +93,6 @@ export function isManagedKeyPair(key: ManagedKey | ManagedKeyPair | undefined):
return key !== undefined && 'privateKey' in key && 'publicKey' in key;
}

/**
* Type guard function to check if the given key is a raw key pair
* of ArrayBuffers.
*
* @param key The key to check.
* @returns True if the key is a pair of key ArrayBuffers, false otherwise.
*/
export function isBufferKeyPair(key: BufferKeyPair | undefined): key is BufferKeyPair {
return (key && 'privateKey' in key && 'publicKey' in key &&
universalTypeOf(key.privateKey) === 'ArrayBuffer' &&
universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false;
}

/**
* Generates a UUID (Universally Unique Identifier) using a
* cryptographically strong random number generator following
Expand Down
88 changes: 0 additions & 88 deletions packages/web5/examples/alice.html

This file was deleted.

0 comments on commit b6db3c8

Please sign in to comment.