### Installing Project Dependencies with Bun Source: https://github.com/edgefirst-dev/data/blob/main/CONTRIBUTING.md Installs all required project dependencies using the Bun package manager. This command should be run once after cloning the repository or when dependencies change. ```Shell bun install ``` -------------------------------- ### Installing @edgefirst-dev/data with Bun Source: https://github.com/edgefirst-dev/data/blob/main/README.md This snippet demonstrates how to install the `@edgefirst-dev/data` library using the Bun package manager. This is the first step required to integrate and use the library in a project. ```Shell bun add @edgefirst-dev/data ``` -------------------------------- ### Verifying Module Exports with Bun Source: https://github.com/edgefirst-dev/data/blob/main/CONTRIBUTING.md Checks the project's module exports to ensure they are correctly configured and accessible. This is important for libraries or packages to guarantee proper consumption by other modules. ```Shell bun run exports ``` -------------------------------- ### Checking Code Quality with Bun Source: https://github.com/edgefirst-dev/data/blob/main/CONTRIBUTING.md Runs the configured code quality checks, typically involving linters and formatters, to enforce coding standards and maintain code consistency across the project. ```Shell bun run quality ``` -------------------------------- ### Running Project Tests with Bun Source: https://github.com/edgefirst-dev/data/blob/main/CONTRIBUTING.md Executes the project's test suite using Bun's test runner. This helps ensure that code changes do not introduce regressions and that existing functionality works as expected. ```Shell bun test ``` -------------------------------- ### Performing Type Checking with Bun Source: https://github.com/edgefirst-dev/data/blob/main/CONTRIBUTING.md Executes the type checker to verify type correctness in the codebase. This is crucial for projects using TypeScript or similar typed languages to catch type-related errors early. ```Shell bun run typecheck ``` -------------------------------- ### Handling Parser Errors in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This example demonstrates how to implement robust error handling for parser operations using `try-catch` blocks. It shows how to specifically catch `Parser.MissingKeyError` and other `Parser.Error` types, allowing for graceful recovery or specific error messages when validation fails. ```TypeScript import { ObjectParser } from "@edgefirst-dev/data/parser"; try { const data = { name: "Alice", age: 30 }; const parser = new ObjectParser(data); console.log(parser.string("email")); // Throws Parser.MissingKeyError } catch (error) { if (error instanceof Parser.MissingKeyError) { // Handle missing key error } if (error instanceof Parser.Error) { // Handle other parser errors } throw error; // Re-throw unexpected errors } ``` -------------------------------- ### Defining and Using a Data DTO with FormParser in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This example demonstrates how to define a custom DTO, `LoginData`, by extending the `Data` class and using `FormParser` to extract `username` and `password` from `FormData`. It shows how to instantiate the DTO with a parser and access its type-safe properties. ```TypeScript import { Data } from "@edgefirst-dev/data"; import { FormParser } from "@edgefirst-dev/data/parser"; class LoginData extends Data { get username() { return this.parser.string("username"); } get password() { return this.parser.string("password"); } } const formData = new FormData(); formData.append("username", "johndoe"); formData.append("password", "secret"); const loginData = new LoginData(new FormParser(formData)); console.log(loginData.username); // "johndoe" console.log(loginData.password); // "secret" ``` -------------------------------- ### Using SearchParamsParser to Extract URL Parameters in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This example illustrates how to use `SearchParamsParser` to extract a query parameter from a `URL` object. It demonstrates accessing URL search parameters in a type-safe manner, ensuring the retrieved value is a string. ```TypeScript import { SearchParamsParser } from "@edgefirst-dev/data/parser"; const url = new URL("https://example.com/?search=query"); const parser = new SearchParamsParser(url); console.log(parser.get("search")); // "query" ``` -------------------------------- ### Importing Parser Classes in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This snippet illustrates how to import the base `Parser` class and its specialized subclasses (`FormParser`, `SearchParamsParser`, `ObjectParser`) from the `parser` module of the `@edgefirst-dev/data` package. These classes are used for parsing and validating data from various structured sources. ```TypeScript import { Parser, FormParser, SearchParamsParser, ObjectParser, } from "@edgefirst-dev/data/parser"; ``` -------------------------------- ### Importing Data Class in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This snippet shows how to import the `Data` class from the `@edgefirst-dev/data` package. The `Data` class is fundamental for defining Data Transfer Objects (DTOs) that structure parsed data. ```TypeScript import { Data } from "@edgefirst-dev/data"; ``` -------------------------------- ### Using ObjectParser to Access Object Properties in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This snippet demonstrates how to use `ObjectParser` to safely access and validate string and number properties from a plain JavaScript object. It shows how to retrieve values with type correctness, preventing common runtime errors. ```TypeScript import { ObjectParser } from "@edgefirst-dev/data/parser"; const data = { name: "Alice", age: 30 }; const parser = new ObjectParser(data); console.log(parser.string("name")); // "Alice" console.log(parser.number("age")); // 30 ``` -------------------------------- ### Using FormParser to Extract Data from FormData in TypeScript Source: https://github.com/edgefirst-dev/data/blob/main/README.md This snippet shows how to use `FormParser` to safely extract a string value from a `FormData` object. It demonstrates the basic usage of `FormParser` for accessing form fields with type validation. ```TypeScript import { FormParser } from "@edgefirst-dev/data/parser"; const formData = new FormData(); formData.append("username", "johndoe"); const parser = new FormParser(formData); console.log(parser.string("username")); // "johndoe" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.