Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -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
111 changes: 111 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading