remove isStringValue
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { isPlainObject, isStringValue } from '../../utils/typeGuards';
|
||||
import { isPlainObject } from '../../utils/typeGuards';
|
||||
|
||||
type ApiClient = {
|
||||
post: (path: string, body?: unknown) => Promise<{ data: unknown }>;
|
||||
@@ -127,7 +127,7 @@ const useDocumentCorrespondentActions = ({
|
||||
if (isPlainObject(option) && 'id' in option) {
|
||||
return option as CorrespondentOption;
|
||||
}
|
||||
if (isStringValue(option)) {
|
||||
if (typeof option === 'string') {
|
||||
const trimmed = option.trim();
|
||||
if (trimmed) {
|
||||
return { id: null, name: trimmed };
|
||||
|
||||
@@ -3,5 +3,4 @@ const objectToString = Object.prototype.toString;
|
||||
export const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
||||
value !== null && !Array.isArray(value) && Object(value) === value;
|
||||
|
||||
export const isStringValue = (value: unknown): value is string =>
|
||||
objectToString.call(value) === '[object String]';
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ type AuthenticationCredential = PublicKeyCredential & {
|
||||
response: AuthenticatorAssertionResponse;
|
||||
};
|
||||
|
||||
import { isStringValue } from './typeGuards';
|
||||
|
||||
const base64urlToBase64 = (value: string = ''): string => {
|
||||
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
||||
const padding = normalized.length % 4;
|
||||
@@ -103,14 +101,14 @@ export const preparePublicKeyCreationOptions = (
|
||||
|
||||
const publicKey: PublicKeyCredentialCreationOptions = { ...challengeResponse.publicKey };
|
||||
|
||||
if (publicKey.challenge && isStringValue(publicKey.challenge)) {
|
||||
if (publicKey.challenge && typeof publicKey.challenge === 'string') {
|
||||
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
||||
}
|
||||
|
||||
if (publicKey.user?.id) {
|
||||
publicKey.user = {
|
||||
...publicKey.user,
|
||||
id: isStringValue(publicKey.user.id)
|
||||
id: typeof publicKey.user.id === 'string'
|
||||
? base64urlToBufferSource(publicKey.user.id)
|
||||
: publicKey.user.id,
|
||||
};
|
||||
@@ -119,7 +117,7 @@ export const preparePublicKeyCreationOptions = (
|
||||
if (Array.isArray(publicKey.excludeCredentials)) {
|
||||
publicKey.excludeCredentials = publicKey.excludeCredentials.map((descriptor) => ({
|
||||
...descriptor,
|
||||
id: isStringValue(descriptor.id)
|
||||
id: typeof descriptor.id === 'string'
|
||||
? base64urlToBufferSource(descriptor.id)
|
||||
: descriptor.id,
|
||||
}));
|
||||
@@ -141,14 +139,14 @@ export const preparePublicKeyRequestOptions = (
|
||||
|
||||
const publicKey: PublicKeyCredentialRequestOptions = { ...challengeResponse.publicKey };
|
||||
|
||||
if (publicKey.challenge && isStringValue(publicKey.challenge)) {
|
||||
if (publicKey.challenge && typeof publicKey.challenge === 'string') {
|
||||
publicKey.challenge = base64urlToBufferSource(publicKey.challenge);
|
||||
}
|
||||
|
||||
if (Array.isArray(publicKey.allowCredentials)) {
|
||||
publicKey.allowCredentials = publicKey.allowCredentials.map((descriptor) => ({
|
||||
...descriptor,
|
||||
id: isStringValue(descriptor.id)
|
||||
id: typeof descriptor.id === 'string'
|
||||
? base64urlToBufferSource(descriptor.id)
|
||||
: descriptor.id,
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user