remove isStringValue

This commit is contained in:
2025-11-24 21:03:06 +01:00
parent d470bc8bf1
commit 63be4663ab
3 changed files with 8 additions and 11 deletions
@@ -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 };
+1 -2
View File
@@ -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]';
+5 -7
View File
@@ -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,
}));