Skip to content

Automatic boolean string conversion#218

Merged
yamcodes merged 2 commits intomainfrom
87-feature-request-support-boolean-type-conversion-for-arkenv
Oct 12, 2025
Merged

Automatic boolean string conversion#218
yamcodes merged 2 commits intomainfrom
87-feature-request-support-boolean-type-conversion-for-arkenv

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Oct 12, 2025

  • Introduced automatic conversion of "true"/"false" strings to boolean values in the arkenv package.
  • Updated documentation to reflect new boolean type behavior and provided examples.
  • Added support for boolean defaults in environment variable definitions.
  • Updated related tests to ensure correct functionality of the new boolean handling.

These changes improve the usability of environment variables in the arkenv package, making it easier to manage boolean configurations.

Closes #87

Summary by CodeRabbit

  • New Features

    • Environment booleans now accept "true"/"false" strings and convert to actual boolean values.
    • Added a DEBUG configuration flag; sample outputs now include its value.
  • Documentation

    • New guide on morphs with examples for boolean coercion and defaults.
    • Updated quickstart and how-to pages to include DEBUG and boolean behavior.
    • Expanded docs navigation with new sections/pages.
  • Tests

    • Added/updated tests covering string-to-boolean conversion and defaults.
  • Chores

    • Updated website deps and example .env entries.

- Introduced automatic conversion of "true"/"false" strings to boolean values in the arkenv package.
- Updated documentation to reflect new boolean type behavior and provided examples.
- Added support for boolean defaults in environment variable definitions.
- Updated related tests to ensure correct functionality of the new boolean handling.

These changes improve the usability of environment variables in the arkenv package, making it easier to manage boolean configurations.
@yamcodes yamcodes linked an issue Oct 12, 2025 that may be closed by this pull request
@changeset-bot
Copy link

changeset-bot bot commented Oct 12, 2025

🦋 Changeset detected

Latest commit: 755500a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
arkenv Patch
@arkenv/vite-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Oct 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Oct 12, 2025 10:22pm

@github-actions github-actions bot added docs Improvements or additions to documentation arkenv Changes to the `arkenv` npm package. www Improvements or additions to arkenv.js.org tests This issue or PR is about adding, removing or changing tests labels Oct 12, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds a new boolean type to arkenv that coerces "true"/"false" strings to booleans, integrates it into scope, updates tests and docs, and demonstrates usage in the Node playground (adds DEBUG). Website docs gain a new “morphs” page and metadata entries; www adds an arktype dependency.

Changes

Cohort / File(s) Summary
Core type addition
packages/arkenv/src/types.ts, packages/arkenv/src/scope.ts
Introduces and exports a boolean type that accepts `"true"
Tests
packages/arkenv/src/type.test.ts
Adds and updates tests to cover string-to-boolean coercion, boolean defaults behavior, invalid inputs, and updated fixtures.
Playground (Node)
apps/playgrounds/node/.env.example, apps/playgrounds/node/index.ts
Adds DEBUG=true to the example env; extends arkenv config with DEBUG: "boolean = true" and logs debug in the playground output.
Docs content
apps/www/content/docs/how-to/load-environment-variables.mdx, apps/www/content/docs/quickstart.mdx, apps/www/content/docs/morphs.mdx
Documents the boolean morph (coercion from strings), shows examples using DEBUG, and adds a new “morphs” page explaining the boolean morph and customization.
Docs metadata
apps/www/content/docs/meta.json
Inserts "---API---" and "morphs" into the site docs pages array.
Site package
apps/www/package.json
Adds arktype dependency.
Changelog
.changeset/silly-animals-fly.md
Adds a changelog entry describing automatic boolean string conversion for arkenv.
Build config
turbo.json
Expands typecheck task dependsOn from ["transit"] to ["transit", "^build"].

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App
  participant ArkEnv as ArkEnv Config
  participant Types as Types.boolean
  participant Env as ProcessEnv

  App->>ArkEnv: define schema { DEBUG: "boolean = true", ... }
  App->>Env: read DEBUG (string or absent)
  alt DEBUG provided as string ("true"/"false")
    ArkEnv->>Types: morph("true"/"false")
    Types-->>ArkEnv: boolean true/false
  else DEBUG not provided
    ArkEnv-->>App: use default true
  end
  ArkEnv-->>App: env.DEBUG (boolean)
  App->>App: use env.DEBUG (logging/runtime)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

I toggled truths from strings so bright,
"true"/"false" now hop into proper light.
In burrows of env I sniff and see—
DEBUG is crunchy, boolean-y.
Thump-thump logs dance; tests clap for me. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning While most changes implement the requested boolean conversion feature and associated documentation, the update to turbo.json’s typecheck dependencies and the addition of the arktype dependency in apps/www/package.json are unrelated to the automatic boolean conversion objectives defined in issue #87. The CI configuration change and new package dependency introduce side effects beyond core feature implementation and lack justification in the PR description. These modifications appear out of scope and should be removed or moved to a separate pull request to maintain a focused review. The CI configuration update and the added package dependency should be extracted into a separate pull request or clearly justified within this PR description to ensure that this changeset remains focused on the boolean conversion feature and associated documentation.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the introduction of automatic boolean string conversion in the arkenv package, which is the primary feature implemented by this pull request, and it does so in a concise and specific manner. It focuses on the main change without including unrelated details, making it easy for reviewers to understand the update at a glance. It accurately conveys the core enhancement and omits extraneous information.
Linked Issues Check ✅ Passed The pull request fully addresses issue #87 by adding an explicit boolean type in the public API that automatically converts "true" and "false" strings to booleans, including support for default values and robust handling of invalid inputs through updated tests. Documentation, examples, and the root scope have been updated to reflect nested boolean support and custom morph usage, aligning with objectives of reliable conversion, explicit typing, edge-case handling, and nested object support. No unrelated functionality has been added, so the implementation adheres to the linked issue’s requirements.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 87-feature-request-support-boolean-type-conversion-for-arkenv

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7776895 and 755500a.

📒 Files selected for processing (1)
  • turbo.json (1 hunks)
🔇 Additional comments (1)
turbo.json (1)

23-24: No cycles detected in Turbo task graph Verified that adding ^build to typecheck dependencies does not introduce any cycles.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/arkenv@218
npm i https://pkg.pr.new/@arkenv/vite-plugin@218

commit: 755500a

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/playgrounds/node/.env.example (1)

4-4: Consider alphabetical ordering for consistency.

The DEBUG key could be placed before HOST to maintain alphabetical ordering, which can improve readability and maintainability of environment variable files.

Apply this diff to reorder alphabetically:

 HOST=localhost
 PORT=3000
 NODE_ENV=development
-DEBUG=true
+DEBUG=true

Actually, to maintain alphabetical order:

+DEBUG=true
 HOST=localhost
+NODE_ENV=development
 PORT=3000
-NODE_ENV=development
-DEBUG=true
packages/arkenv/src/types.ts (1)

21-29: LGTM! Clean boolean conversion implementation.

The type definition correctly handles both string ("true"/"false") and boolean literal inputs, converting them to actual booleans. The morph function logic is sound: str === "true" || str === true correctly returns true for "true" or true, and false for "false" or false.

Optional refinement: The JSDoc could be more concise:

 /**
- * A boolean that accepts string values and converts them to boolean
- * Accepts "true" or "false" strings and converts them to actual boolean values
+ * Accepts "true"/"false" strings or boolean literals and converts them to boolean
  */
packages/arkenv/src/type.test.ts (1)

202-217: Excellent test for boolean defaults and overrides.

This test comprehensively verifies:

  1. Default boolean values are applied when no environment variables are provided
  2. String values ("true"/"false") correctly override the defaults

The test follows the coding guidelines by using the describe/it structure and testing success cases.

Minor enhancement: Consider adding a test case for invalid overrides to ensure proper error handling:

// Test with invalid override (should throw)
expect(() => envType.assert({ DEBUG: "invalid" })).toThrow();

Based on coding guidelines (test both success and failure cases).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c65f24 and 7776895.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • .changeset/silly-animals-fly.md (1 hunks)
  • apps/playgrounds/node/.env.example (1 hunks)
  • apps/playgrounds/node/index.ts (2 hunks)
  • apps/www/content/docs/how-to/load-environment-variables.mdx (1 hunks)
  • apps/www/content/docs/meta.json (1 hunks)
  • apps/www/content/docs/morphs.mdx (1 hunks)
  • apps/www/content/docs/quickstart.mdx (2 hunks)
  • apps/www/package.json (1 hunks)
  • packages/arkenv/src/scope.ts (2 hunks)
  • packages/arkenv/src/type.test.ts (5 hunks)
  • packages/arkenv/src/types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.test.ts: Place tests alongside source files and use the .test.ts suffix (e.g., create-env.test.ts, types.test.ts, errors.test.ts, utils.test.ts)
Use Vitest's describe/it structure in tests
Test both success and failure cases for environment validation and utilities
Mock process.env to cover different environment scenarios in tests
In tests, save and restore process.env in setup/teardown (beforeEach/afterEach) to avoid leakage between cases
Verify both runtime behavior and TypeScript types in tests

Files:

  • packages/arkenv/src/type.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : Test both success and failure cases for environment validation and utilities

Applied to files:

  • packages/arkenv/src/type.test.ts
🧬 Code graph analysis (4)
apps/www/content/docs/quickstart.mdx (1)
packages/arkenv/src/index.test.ts (1)
  • vi (37-47)
apps/playgrounds/node/index.ts (2)
packages/arkenv/src/index.test.ts (4)
  • vi (25-35)
  • vi (65-81)
  • vi (37-47)
  • arkenv (50-53)
packages/arkenv/src/create-env.test.ts (1)
  • env (88-99)
packages/arkenv/src/types.ts (2)
packages/arkenv/src/type.ts (1)
  • type (3-3)
packages/arkenv/src/scope.test.ts (1)
  • stringType (46-50)
packages/arkenv/src/type.test.ts (1)
packages/arkenv/src/type.ts (1)
  • type (3-3)
🪛 dotenv-linter (3.3.0)
apps/playgrounds/node/.env.example

[warning] 4-4: [UnorderedKey] The DEBUG key should go before the HOST key

(UnorderedKey)

🔇 Additional comments (14)
apps/www/content/docs/quickstart.mdx (1)

47-49: LGTM! Clear documentation of the boolean type.

The addition of the DEBUG boolean environment variable with its explanatory comment is clear and demonstrates the new boolean string conversion feature effectively.

Also applies to: 77-77

apps/www/package.json (1)

26-26: LGTM! Appropriate dependency addition.

Adding arktype as a direct dependency is appropriate for the documentation site, as it likely needs to import and demonstrate arktype features in examples.

apps/www/content/docs/how-to/load-environment-variables.mdx (1)

187-189: LGTM! Comprehensive documentation update.

The addition of the DEBUG boolean example with a clear explanatory comment effectively demonstrates the new boolean string conversion feature in a practical context.

apps/www/content/docs/meta.json (1)

7-8: LGTM! Appropriate navigation structure.

Adding the API section header and morphs page entry properly integrates the new documentation into the site navigation.

apps/www/content/docs/morphs.mdx (1)

1-63: LGTM! Excellent documentation of the morphs feature.

The documentation clearly explains:

  • What morphs are and why they exist
  • The boolean morph behavior with string-to-boolean conversion
  • How to set boolean defaults
  • How to customize behavior with custom morph functions

The examples are practical and include expected outputs, making it easy for users to understand and implement.

.changeset/silly-animals-fly.md (1)

1-29: LGTM! Clear and informative changelog entry.

The changeset appropriately documents the new boolean string conversion feature as a patch release with a clear example demonstrating the functionality.

packages/arkenv/src/scope.ts (1)

18-18: boolean type correctly defined without type.module()
Verified that boolean is exported via type() in packages/arkenv/src/types.ts and has no nested boolean.* usages, so no module wrapper is needed.

packages/arkenv/src/type.test.ts (5)

17-21: LGTM! Correctly tests string-to-boolean conversion.

The test now validates that the string "true" is converted to the boolean true, which aligns with the new boolean type behavior.


23-27: Good coverage of string-to-boolean conversion.

This test complements the existing "true" test by verifying that the string "false" converts to the boolean false.

However, consider adding explicit tests for boolean literal inputs to ensure the type also accepts true and false as direct boolean values (not just strings). This would provide complete coverage of the type signature "'true' | 'false' | true | false".

Example test to add:

it("should accept boolean literals", () => {
  const envType = type({ DEBUG: "boolean" });
  const result1 = envType.assert({ DEBUG: true });
  expect(result1.DEBUG).toBe(true);
  
  const result2 = envType.assert({ DEBUG: false });
  expect(result2.DEBUG).toBe(false);
});

Based on coding guidelines (test both success and failure cases).


86-108: LGTM! Consistent with string-to-boolean behavior.

The update to use string "true" instead of boolean true is consistent with the new boolean type behavior and ensures the test validates the string-to-boolean conversion in a complex type scenario.


121-130: LGTM! Properly tests invalid boolean input.

Changing from true (which is now valid) to "invalid" correctly tests the failure case, ensuring that only the allowed values ("true", "false", true, false) are accepted by the boolean type.


171-190: LGTM! Consistent test update.

The change aligns with the new boolean type behavior, testing string-to-boolean conversion alongside other type validations.

apps/playgrounds/node/index.ts (2)

8-8: LGTM! Proper usage of the new boolean type.

The DEBUG environment variable correctly uses the new boolean type with a default value. The inline default syntax "boolean = true" is appropriate and will accept "true"/"false" strings from environment variables while defaulting to true when not provided.

Note: This uses inline default syntax while ALLOWED_ORIGINS uses the functional default syntax .default(() => []). Both are valid, though the codebase now has two different default patterns. This is a minor stylistic observation and doesn't require changes.


17-24: LGTM! Consistent pattern and proper integration.

The debug variable extraction and console.log update follow the same pattern as the other environment variables. The TypeScript types are properly inferred, ensuring type safety throughout.

- Ensure build before typecheck
@yamcodes yamcodes merged commit e554e2b into main Oct 12, 2025
18 checks passed
@yamcodes yamcodes deleted the 87-feature-request-support-boolean-type-conversion-for-arkenv branch October 12, 2025 22:27
@arkenv-bot arkenv-bot bot mentioned this pull request Oct 12, 2025
yamcodes pushed a commit that referenced this pull request Oct 12, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## arkenv@0.7.3

### Patch Changes

- #### Automatic boolean string conversion
_[`#218`](#218)
[`e554e2b`](e554e2b)
[@yamcodes](https://github.com/yamcodes)_

The `boolean` type now accepts `"true"`/`"false"` strings from
environment variables and converts them to actual boolean values. This
also works with boolean defaults.

    Example:

    ```ts
    import arkenv from "arkenv";

    const env = arkenv({
      DEBUG: "boolean",
      ENABLE_FEATURE: "boolean = true",
    });

    console.log(env.DEBUG);
    console.log(env.ENABLE_FEATURE);
    ```

    Result:

    ```sh
    ❯ DEBUG=true npx tsx index.ts
    true
    true
    ```

## @arkenv/vite-plugin@0.0.13

### Patch Changes

- #### Support Vite 2.x
_[`#212`](#212)
[`bfe08f6`](bfe08f6)
[@yamcodes](https://github.com/yamcodes)_

Extended the supported Vite versions to include **2.9.18** through
**7.x** (inclusive).

Also, we've added the `vite-plugin` keyword to the `package.json`, and a
section in the `README.md` explaining why this plugin is a Vite only
plugin (and not a Rollup plugin).

<details><summary>Updated 1 dependency</summary>

<small>


[`e554e2b`](e554e2b)

</small>

-   `arkenv@0.7.3`

</details>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
yamcodes pushed a commit that referenced this pull request Nov 10, 2025
This PR contains the following updates:

| Package | Change | Age | Confidence |
|---|---|---|---|
| [arkenv](https://arkenv.js.org)
([source](https://redirect.github.com/yamcodes/arkenv)) | [`0.7.0` ->
`0.7.3`](https://renovatebot.com/diffs/npm/arkenv/0.7.0/0.7.3) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/arkenv/0.7.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/arkenv/0.7.0/0.7.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>yamcodes/arkenv (arkenv)</summary>

###
[`v0.7.3`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.3)

[Compare
Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.2...arkenv@0.7.3)

##### Patch Changes

- #### Automatic boolean string conversion
*[`#218`](https://redirect.github.com/yamcodes/arkenv/pull/218)
[`e554e2b`](https://redirect.github.com/yamcodes/arkenv/commit/e554e2b41aab1b8e29d873982ea587c069f4732d)
[@&#8203;yamcodes](https://redirect.github.com/yamcodes)*

The `boolean` type now accepts `"true"`/`"false"` strings from
environment variables and converts them to actual boolean values. This
also works with boolean defaults.

  Example:

  ```ts
  import arkenv from "arkenv";

  const env = arkenv({
    DEBUG: "boolean",
    ENABLE_FEATURE: "boolean = true",
  });

  console.log(env.DEBUG);
  console.log(env.ENABLE_FEATURE);
  ```

  Result:

  ```sh
  ❯ DEBUG=true npx tsx index.ts
  true
  true
  ```

###
[`v0.7.2`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.2)

[Compare
Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.1...arkenv@0.7.2)

##### Patch Changes

- #### Support array defaults using type().default() syntax
*[`#199`](https://redirect.github.com/yamcodes/arkenv/pull/199)
[`e50dba1`](https://redirect.github.com/yamcodes/arkenv/commit/e50dba1f19418f8fc007dc786df1172067e3d07c)
[@&#8203;copilot-swe-agent](https://redirect.github.com/apps/copilot-swe-agent)*

Fix to an issue where `type("array[]").default(() => [...])` syntax was
not accepted by `createEnv` due to overly restrictive type constraints.
The function now accepts any string-keyed record while still maintaining
type safety through ArkType's validation system.

  ##### New Features

- Array defaults to empty using `type("string[]").default(() => [])`
syntax
  - Support for complex array types with defaults
  - Mixed schemas combining string-based and type-based defaults

  ##### Example

  ```typescript
  const env = arkenv({
    ALLOWED_ORIGINS: type("string[]").default(() => ["localhost"]),
    FEATURE_FLAGS: type("string[]").default(() => []),
    PORT: "number.port",
  });
  ```

###
[`v0.7.1`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.1)

[Compare
Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.0...arkenv@0.7.1)

##### Patch Changes

- Export `ArkEnvError`
*[`#161`](https://redirect.github.com/yamcodes/arkenv/pull/161)
[`221f9ef`](https://redirect.github.com/yamcodes/arkenv/commit/221f9efdef65691b0c5155b12ec460404dddbe82)
[@&#8203;yamcodes](https://redirect.github.com/yamcodes)*

  You can now import `ArkEnvError` from `arkenv`:

  ```ts
  import { ArkEnvError } from "arkenv";
  ```

- Improve JSDoc
*[`#161`](https://redirect.github.com/yamcodes/arkenv/pull/161)
[`221f9ef`](https://redirect.github.com/yamcodes/arkenv/commit/221f9efdef65691b0c5155b12ec460404dddbe82)
[@&#8203;yamcodes](https://redirect.github.com/yamcodes)*

  The JSDoc for `arkenv` and `createEnv` is now more descriptive.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on friday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/yamcodes/arkenv).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNTkuNCIsInVwZGF0ZWRJblZlciI6IjQxLjE1OS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arkenv Changes to the `arkenv` npm package. docs Improvements or additions to documentation tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support Boolean Type Conversion for ArkEnv

1 participant