Renamed nullable utils into isDefined and isUndefinedOrNull (#4402)
* Renamed nullable utils into isDefined and isUndefinedOrNull
This commit is contained in:
15
packages/twenty-front/src/utils/__tests__/isDefined.test.ts
Normal file
15
packages/twenty-front/src/utils/__tests__/isDefined.test.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
describe('isDefined', () => {
|
||||
it('returns true if value is not undefined nor null', () => {
|
||||
expect(isDefined('')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if value is null', () => {
|
||||
expect(isDefined(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if value is undefined', () => {
|
||||
expect(isDefined(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
import { isNonNullable } from '~/utils/isNonNullable';
|
||||
|
||||
describe('isNonNullable', () => {
|
||||
it('returns true if value is not undefined nor null', () => {
|
||||
expect(isNonNullable('')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false if value is null', () => {
|
||||
expect(isNonNullable(null)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false if value is undefined', () => {
|
||||
expect(isNonNullable(undefined)).toBe(false);
|
||||
});
|
||||
});
|
||||
@ -1,6 +1,6 @@
|
||||
import { LinkType } from '@/ui/navigation/link/components/SocialLink';
|
||||
|
||||
import { isNonNullable } from './isNonNullable';
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
export const checkUrlType = (url: string) => {
|
||||
if (
|
||||
@ -11,9 +11,7 @@ export const checkUrlType = (url: string) => {
|
||||
return LinkType.LinkedIn;
|
||||
}
|
||||
if (
|
||||
isNonNullable(
|
||||
/^((http|https):\/\/)?(?:www\.)?twitter\.com\/(\w+)?/i.exec(url),
|
||||
)
|
||||
isDefined(/^((http|https):\/\/)?(?:www\.)?twitter\.com\/(\w+)?/i.exec(url))
|
||||
) {
|
||||
return LinkType.Twitter;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { LinkType } from '@/ui/navigation/link/components/SocialLink';
|
||||
|
||||
import { isNonNullable } from './isNonNullable';
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
type getUrlDisplayValueByUrlTypeProps = {
|
||||
type: LinkType;
|
||||
@ -15,7 +15,7 @@ export const getDisplayValueByUrlType = ({
|
||||
const matches = href.match(
|
||||
/(?:https?:\/\/)?(?:www.)?linkedin.com\/(?:in|company|school)\/(.*)/,
|
||||
);
|
||||
if (isNonNullable(matches?.[1])) {
|
||||
if (isDefined(matches?.[1])) {
|
||||
return matches?.[1];
|
||||
} else {
|
||||
return 'LinkedIn';
|
||||
@ -26,7 +26,7 @@ export const getDisplayValueByUrlType = ({
|
||||
const matches = href.match(
|
||||
/(?:https?:\/\/)?(?:www.)?twitter.com\/([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
|
||||
);
|
||||
if (isNonNullable(matches?.[1])) {
|
||||
if (isDefined(matches?.[1])) {
|
||||
return `@${matches?.[1]}`;
|
||||
} else {
|
||||
return '@twitter';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { isNonNullable } from './isNonNullable';
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
export const isDomain = (url: string | undefined | null) =>
|
||||
isNonNullable(url) &&
|
||||
isDefined(url) &&
|
||||
/^((?!-))(xn--)?[a-z0-9][a-z0-9-_]{0,61}[a-z0-9]{0,1}\.(xn--)?([a-z0-9-]{1,61}|[a-z0-9-]{1,30}\.[a-z]{2,})$/.test(
|
||||
url,
|
||||
);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { isNonNullable } from './isNonNullable';
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
export const isURL = (url: string | undefined | null) =>
|
||||
isNonNullable(url) &&
|
||||
isDefined(url) &&
|
||||
url.match(
|
||||
/^(https?:\/\/)?(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i,
|
||||
);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { isNull, isUndefined } from '@sniptt/guards';
|
||||
|
||||
export const isNonNullable = <T>(value: T): value is NonNullable<T> =>
|
||||
export const isDefined = <T>(value: T): value is NonNullable<T> =>
|
||||
!isUndefined(value) && !isNull(value);
|
||||
@ -1,4 +1,4 @@
|
||||
import { isNull, isUndefined } from '@sniptt/guards';
|
||||
|
||||
export const isNullable = (value: any): value is null | undefined =>
|
||||
export const isUndefinedOrNull = (value: any): value is null | undefined =>
|
||||
isUndefined(value) || isNull(value);
|
||||
@ -2,7 +2,7 @@ import { AtomEffect } from 'recoil';
|
||||
|
||||
import { cookieStorage } from '~/utils/cookie-storage';
|
||||
|
||||
import { isNonNullable } from './isNonNullable';
|
||||
import { isDefined } from './isDefined';
|
||||
|
||||
export const localStorageEffect =
|
||||
<T>(key: string): AtomEffect<T> =>
|
||||
@ -24,8 +24,8 @@ export const cookieStorageEffect =
|
||||
({ setSelf, onSet }) => {
|
||||
const savedValue = cookieStorage.getItem(key);
|
||||
if (
|
||||
isNonNullable(savedValue) &&
|
||||
isNonNullable(JSON.parse(savedValue)['accessToken'])
|
||||
isDefined(savedValue) &&
|
||||
isDefined(JSON.parse(savedValue)['accessToken'])
|
||||
) {
|
||||
setSelf(JSON.parse(savedValue));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user