Skip to content

Commit

Permalink
Address feddback
Browse files Browse the repository at this point in the history
  • Loading branch information
ioanabrooks committed Jan 26, 2023
1 parent 5a45b23 commit d80dc7c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
1 change: 0 additions & 1 deletion packages/ui/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './authenticator';
export * from './accountSettings';
export * from './storage';
export * from './typeGuards';
export { getLogger } from './utils';
23 changes: 0 additions & 23 deletions packages/ui/src/helpers/typeGuards.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './i18n';
export * from './machines';
export * from './theme';
export * from './types';
export * from './utils';
2 changes: 1 addition & 1 deletion packages/ui/src/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kebabCase from 'lodash/kebabCase';
// internal style dictionary function
import usesReference from 'style-dictionary/lib/utils/references/usesReference';

import { isObject, isString } from '../helpers/typeGuards';
import { isObject, isString } from '../utils';
import {
DesignToken,
ShadowValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject, isString, isUndefined } from '../typeGuards';
import { isObject, isString, isUndefined } from '..';

describe('isObject', () => {
it('should return `true` for objects', () => {
Expand Down Expand Up @@ -28,20 +28,22 @@ describe('isString', () => {
it('should return `true` for strings', () => {
expect(isString('')).toStrictEqual(true);
expect(isString('test')).toStrictEqual(true);
expect(isString(new String('test'))).toStrictEqual(true);
});

it('should return `false` for non-strings', () => {
expect(isString(null)).toStrictEqual(false);
expect(isString(undefined)).toStrictEqual(false);
expect(isString(true)).toStrictEqual(false);
expect(isString(0)).toStrictEqual(false);
expect(isString(new String(''))).toStrictEqual(false);
expect(isString([1, 2, 3])).toStrictEqual(false);
});
});

describe('isUndefined', () => {
it('should return `true` for undefined values', function () {
expect(isUndefined(undefined)).toStrictEqual(true);
expect(isUndefined(void 0)).toStrictEqual(true);
});

it('should return `false` for non-undefined values', function () {
Expand Down
35 changes: 35 additions & 0 deletions packages/ui/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Checks if `value` is an Object (non-primitive, non-array, non-function)
* Will return false for Arrays and functions
*
*
* @param {unknown} value The value to check
* @returns {boolean} Returns `true` if `value` is an object, `false` otherwise
*/
export function isObject(value: unknown): value is object {
return value != null && !Array.isArray(value) && typeof value === 'object';
}

/**
* Checks if `value` is a string primitive or object
*
* @param {unknown} value The value to check
* @returns {boolean} Returns `true` if `value` is a string, `false` otherwise
*/
export function isString(value: unknown): value is string {
return (
typeof value === 'string' ||
(typeof value === 'object' &&
Object.prototype.toString.call(value) === '[object String]')
);
}

/**
* Checks if `value` is undefined
*
* @param {unknown} value The value to check
* @returns {boolean} Returns `true` if `value` is undefined, `false` otherwise
*/
export function isUndefined(value: unknown): value is undefined {
return value === undefined;
}

0 comments on commit d80dc7c

Please sign in to comment.