How sumithemmadi/truecallerjs works
Main Components
• Core Library Functions: The source files under the "src" directory (e.g., src/index.ts, src/search.ts, src/login.ts, src/verifyOtp.ts) represent the core business logic, handling API communication, data processing, and formatting.
• Data Module: The "src/data" folder, which contains static JSON files (such as continents.json, countries.json, languages.json, phones.json) and TypeScript files, represents auxiliary data used by the library.
• Command Line Interface (CLI): The CLI entry point found in src/cli.ts allows the library to be executed from the command line. This component takes user input, processes command options (like login, search, and bulk search), and then calls the appropriate library functions.
• Testing & Distribution: The "test" directory contains test scripts ensuring the functions (login, verifyOtp, search, bulkSearch) work as expected. The "dist" directory shows the compiled output, including both CommonJS and potential module formats, which represents the packaged production version of the library.
• Configuration & Build Tools: Various configuration files (.babelrc.json, .eslintrc.json, tsconfig.json, jest.config.ts, etc.) indicate the use of TypeScript, ESLint, Prettier, and Jest. These parts are essential for development, testing, and ensuring code quality.
Relationships and Interactions
• The CLI acts as an entry point for end-users, parsing command-line inputs and dispatching commands via the core library functions.
• The core functions (search, login, bulkSearch, verifyOtp) interface with the external Truecaller service (not shown as internal code but implied by the API integration described in the README).
• The data files and static JSON assets are used within the core functionality to provide supporting data (like phone number formatting or country details).
• The build pipeline takes source files (src) and generates a distributable version (in dist) that is consumable as a library through an npm package.
• Testing ensures that inputs through both the CLI and the library methods produce the correct outputs.
Architectural Patterns and Technologies
• Modularity: The separation between the CLI (src/cli.ts) and the core library functions (src/index.ts, src/search.ts, etc.) shows a clear modular design.
• API Abstraction: The library abstracts the Truecaller API details, exposing simple functions (e.g., search and bulk search) to the user.
• Compatibility: Support for Node.js, JavaScript, and TypeScript as indicated by multiple type definitions (.d.ts files) and configurations.
• Build and Test Integration: The use of tools like Babel, ESLint, Prettier, and Jest is integral to the development process.