Skip to content

Commit

Permalink
refactor: remove dynamic imports in favor of direct exports
Browse files Browse the repository at this point in the history
- Remove dynamicImports.ts and use direct exports in barrel files

- Update example files to use direct import pattern

- Update JSDoc examples to show correct import paths

- Remove index.d.ts as it's no longer needed

- Clean up tsconfig.json includes
  • Loading branch information
mherod committed Jan 4, 2025
1 parent aa6f288 commit 812b5ea
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 289 deletions.
60 changes: 22 additions & 38 deletions examples/advanced-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,52 @@

/**
* @description
* This example demonstrates advanced usage of the getCookie function.
* It shows how to retrieve cookies using browser-specific strategies
* and URL-based cookie retrieval.
* This example demonstrates advanced usage of the cookie retrieval functions.
* It shows how to retrieve cookies using different patterns and filters.
* @internal
* @example
* ```typescript
* import { getCookie } from "../src";
* import { getCookie } from "@mherod/get-cookie";
*
* // Get the cookie retrieval function
* const getCookieFn = await getCookie();
*
* // Get a cookie by name and domain
* const cookie = await getCookieFn({
* name: "session",
* // Get all cookies for a domain
* const cookies = await getCookie({
* name: "*",
* domain: "github.com"
* });
*
* console.log(cookie);
* // Get specific cookies
* const authCookie = await getCookie({
* name: "auth",
* domain: "api.github.com"
* });
* ```
*/

import { getCookie } from "../src";

/**
* @description
* Demonstrates browser-specific cookie retrieval examples.
* Run advanced examples of cookie retrieval.
* @internal
* @returns A promise that resolves when all examples have completed.
*/
export async function browserSpecificExamples(): Promise<void> {
// Get the cookie retrieval function
const getCookieFn = await getCookie();

// Get a cookie by name and domain
const cookie = await getCookieFn({
name: "user_session",
export async function runAdvancedExamples(): Promise<void> {
// Example 1: Get a specific cookie by name and domain
const cookie = await getCookie({
name: "session",
domain: "github.com",
});

console.log("Cookie:", cookie);
}

/**
* @description
* Demonstrates URL-based cookie retrieval examples.
* @internal
* @returns A promise that resolves when all examples have completed.
*/
export async function urlBasedExamples(): Promise<void> {
// Get the cookie retrieval function
const getCookieFn = await getCookie();
console.log("Example 1 - Specific cookie:", cookie);

// Get a cookie by name and domain
const cookie = await getCookieFn({
name: "user_session",
// Example 2: Get all cookies for a domain using wildcard
const cookies = await getCookie({
name: "*",
domain: "github.com",
});

console.log("Cookie:", cookie);
console.log("Example 2 - All domain cookies:", cookies);
}

// Execute the examples
Promise.all([browserSpecificExamples(), urlBasedExamples()]).catch(
console.error,
);
runAdvancedExamples().catch(console.error);
16 changes: 5 additions & 11 deletions examples/basic-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
/**
* @description
* This example demonstrates basic usage of the getCookie function.
* It shows how to retrieve cookies from Chrome and Firefox browsers.
* It shows how to retrieve cookies from all supported browsers using a unified interface.
* @internal
* @example
* ```typescript
* import { getCookie } from "../src";
*
* // Get the cookie retrieval function
* const getCookieFn = await getCookie();
* import { getCookie } from "@mherod/get-cookie";
*
* // Get a cookie by name and domain
* const cookie = await getCookieFn({
* const cookie = await getCookie({
* name: "session",
* domain: "github.com"
* });
Expand All @@ -34,12 +31,9 @@ import { getCookie } from "../src";
* @returns A promise that resolves when all examples have completed.
*/
export async function runBasicExamples(): Promise<void> {
// Get the cookie retrieval function
const getCookieFn = await getCookie();

// Get a cookie by name and domain
const cookie = await getCookieFn({
name: "user_session",
const cookie = await getCookie({
name: "session",
domain: "github.com",
});

Expand Down
92 changes: 0 additions & 92 deletions src/core/cookies/dynamicImports.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/core/cookies/getChromeCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { ChromeCookieQueryStrategy } from "../browsers/chrome/ChromeCookieQueryS
* to the console without throwing to the caller
* @example
* ```typescript
* import { getChromeCookie } from "@mherod/get-cookie";
*
* // Get all cookies named "sessionId" from Chrome
* const cookies = await getChromeCookie({ name: "sessionId" });
*
Expand Down Expand Up @@ -42,7 +44,7 @@ export async function getChromeCookie(
* Default export of the getChromeCookie function.
* @example
* ```typescript
* import getChromeCookie from './getChromeCookie';
* import { getChromeCookie } from "@mherod/get-cookie";
* const cookies = await getChromeCookie({
* name: "sessionId",
* domain: "example.com"
Expand Down
4 changes: 3 additions & 1 deletion src/core/cookies/getCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { queryCookies } from "./queryCookies";
* to the console without throwing to the caller
* @example
* ```typescript
* import { getCookie } from "@mherod/get-cookie";
*
* // Get all cookies named "sessionId"
* const cookies = await getCookie({ name: "sessionId" });
* // Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
Expand Down Expand Up @@ -45,7 +47,7 @@ export async function getCookie(
* Default export of the getCookie function.
* @example
* ```typescript
* import getCookie from './getCookie';
* import { getCookie } from "@mherod/get-cookie";
* const authCookies = await getCookie({
* name: "auth-token",
* domain: "api.example.com"
Expand Down
4 changes: 3 additions & 1 deletion src/core/cookies/getFirefoxCookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { FirefoxCookieQueryStrategy } from "../browsers/firefox/FirefoxCookieQue
* to the console without throwing to the caller
* @example
* ```typescript
* import { getFirefoxCookie } from "@mherod/get-cookie";
*
* // Get all cookies named "sessionId" from Firefox
* const cookies = await getFirefoxCookie({ name: "sessionId" });
*
Expand Down Expand Up @@ -45,7 +47,7 @@ export async function getFirefoxCookie(
* Default export of the getFirefoxCookie function.
* @example
* ```typescript
* import getFirefoxCookie from './getFirefoxCookie';
* import { getFirefoxCookie } from "@mherod/get-cookie";
* const sessionCookies = await getFirefoxCookie({
* name: "PHPSESSID",
* domain: "example.com"
Expand Down
Loading

0 comments on commit 812b5ea

Please sign in to comment.