diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..73b6471 --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,46 @@ +name: "Copilot Setup Steps" + +# Automatically run the setup steps when they are changed to allow for easy validation, and +# allow manual testing through the repository's "Actions" tab +on: + workflow_dispatch: + pull_request: + branches: [main, dev] + paths: + - .github/workflows/copilot-setup-steps.yml + +jobs: + # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. + copilot-setup-steps: + runs-on: ubuntu-latest + + # Set the permissions to the lowest permissions possible needed for your steps. + # Copilot will be given its own token for its operations. + permissions: + # If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete. + contents: read + + # You can define any steps you want, and they will run before the agent starts. + # If you do not check out your code, Copilot will do this for you. + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Setup Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + cache: true + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Cache dependencies + run: deno install diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..00d94b3 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,111 @@ +# Base64 - Agent Guide + +## Project Overview + +Base64 is a lightweight, zero-dependency base64 encoding/decoding library for JavaScript and TypeScript that works across Node.js, Deno, Bun, and browsers. It supports both regular base64 and base64url encoding with string and ArrayBuffer conversions. + +## Project Structure + +``` +base64/ +├── src/ # Source code +│ └── base64.ts # Main entry point with all base64 functions +├── tests/ # Test files +│ └── base64.test.ts # Test suite +├── build/ # Build scripts +├── docs/ # Documentation (Jekyll site) +│ ├── index.md +│ ├── installation.md +│ ├── examples.md +│ └── contributing.md +└── deno.json # Deno configuration and tasks +``` + +## Development Environment + +The project uses **Deno** as the primary development runtime, with cross-runtime support for Node.js and Bun. + +### Setup +```bash +# Install Deno dependencies +deno install +``` + +## Contribution Guidelines + +### Pre-commit Checks + +Before committing changes, always run: +```bash +deno fmt +deno lint +deno check src/base64.ts +``` + +This ensures: +- **Formatting**: Code follows style guidelines +- **Linting**: Code quality checks pass +- **Type checking**: TypeScript types are valid + +### Testing + +Run tests during development: +```bash +deno test +``` + +**Note**: The project uses CI workflows from `@cross-org/workflows` for cross-runtime testing (Node.js, Deno, and Bun). These workflows are imported in `.github/workflows/test.yml`. + +### Bun testing equivalent to CI + +```bash +# Prerequisites +bun x jsr add @cross/test @std/assert + +# Run tests +bun test +``` + +### Node testing equivalent to CI + +package.json must be created with `"type": "module"` + +```bash +# Prerequisites +npx jsr add @cross/test @std/assert + +# Run tests +npx --yes tsx --test tests/*.test.ts +``` + +### Full Build + +Before submitting a PR, run the full build to ensure all checks pass: +```bash +deno task build +``` + +This runs all tests, builds distribution files for npm, and validates the entire codebase. + +### Key Points + +- Base work on the `main` or `dev` branch +- Add test cases for all changes +- Zero dependencies - do not add external dependencies +- Follow existing code style and patterns +- Update documentation if changing public APIs +- The library should work across Node.js, Deno, Bun, and browsers + +For detailed contribution guidelines, see [docs/contributing.md](docs/contributing.md). + +## API Overview + +The library exports a single `base64` object with the following methods: + +- `fromArrayBuffer(buffer, urlMode)` - Encodes ArrayBuffer to base64/base64url +- `toArrayBuffer(str, urlMode)` - Decodes base64/base64url to ArrayBuffer +- `fromString(str, urlMode)` - Encodes string to base64/base64url +- `toString(str, urlMode)` - Decodes base64/base64url to string +- `validate(str, urlMode)` - Validates base64/base64url strings + +All methods support an optional `urlMode` parameter to switch between standard base64 and base64url encoding. diff --git a/src/base64.ts b/src/base64.ts index 92ad487..4a8652e 100644 --- a/src/base64.ts +++ b/src/base64.ts @@ -122,7 +122,7 @@ function toString(str: string, urlMode?: boolean): string { string */ function fromString(str: string, urlMode?: boolean): string { - return fromArrayBuffer(new TextEncoder().encode(str), urlMode); + return fromArrayBuffer(new TextEncoder().encode(str).buffer, urlMode); } /**