Files
self/app/docs/examples/tree-shaking/optimal-pattern-example.ts
Justin Hernandez 03635abaaf chore: add kmp license headers; update license year range (#1752)
* add kmp license headers and update year

* formatting
2026-02-15 16:56:06 -08:00

41 lines
1.4 KiB
TypeScript

// SPDX-FileCopyrightText: 2025-2026 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
// Import constants from the constants module
import {
API_URL,
countryCodes,
PASSPORT_ATTESTATION_ID,
} from '@selfxyz/common/constants';
// Import types (these are eliminated during compilation anyway)
import type { PassportData } from '@selfxyz/common/types';
// Import utilities from the utils module
import { generateCommitment, hash } from '@selfxyz/common/utils';
// Example: A real-world function that uses multiple imports efficiently
export function processPassportData(passportData: PassportData): {
commitment: string;
hash: string;
apiEndpoint: string;
isValidCountry: boolean;
} {
return {
// Note: These are simplified examples - real usage requires proper parameters
commitment: 'mock-commitment', // generateCommitment needs secret, attestation_id, passportData
hash: 'mock-hash', // hash needs hashFunction, bytesArray, format parameters
apiEndpoint: API_URL,
// Extract country code from MRZ (positions 2-4 in passport MRZ)
isValidCountry: Object.keys(countryCodes).includes(
passportData.mrz?.slice(2, 5) || '',
),
};
}
// This pattern provides:
// ✅ Minimal bundle size
// ✅ Clear dependency tracking
// ✅ Excellent tree shaking
// ✅ Type safety
// ✅ IDE autocomplete and refactoring support