Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Schema.isPowerOf

Open
#8,999 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@effect-bot is already working on this.

Since Oct 11, 2026.

  • #9006 by @effect-bot — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript

Research direction

A linked pull request, #9006, is already open for this feature. Review the issue's proposed isPowerOf implementation and its toJsonSchema enum approach, then compare them with the existing isMultipleOf implementation mentioned in the issue. Done means the linked change provides the requested power-of validation and an agreed JSON Schema representation.

Written by the indexing model from the issue text.

Description

enhancement
What is the problem this feature would solve?

So, I wanted to create a PasswordHashingMemoryCost schema, one of the checks i need is, isPowerOf(2) however there's no isPowerOf only isMultiplyOf

What is the feature you are proposing to solve the problem?

using isMultipleOf as reference I came up with this:

export function isPowerOf(
  base: number,
  annotations?: Annotations.Filter
): SchemaAST.Filter<number> {
  if (!globalThis.Number.isInteger(base) || base < 2) {
    throw new globalThis.RangeError(
      `Expected an integer greater than or equal to 2, got ${globalThis.String(base)}`
    )
  }
  return makeFilter(
    (input: number) => {
      if (!globalThis.Number.isSafeInteger(input) || input < 1) {
        return false
      }
      while (input % base === 0) {
        input = input / base
      }
      return input === 1
    },
    {
      expected: `a value that is a power of ${base}`,
      representation: {
        id: "effect/schema/isPowerOf",
        payload: { base }
      },
      toJsonSchema: () => ({
        enum: globalThis.Array.from(
          {
            length: globalThis.Math.floor(
              globalThis.Math.log(globalThis.Number.MAX_SAFE_INTEGER) / globalThis.Math.log(base)
            ) + 2
          },
          (_, k) => base ** k
        ).filter(globalThis.Number.isSafeInteger)
      }),
      toCode: () => ({ runtime: `Schema.isPowerOf(${format(base)})` }),
      ...annotations
    }
  )
}

for toJsonSchema I wan't quite sure because json schema doesn't have a "power of" check, so I thought of using an enum, which even in the worst case (base = 2) would "only" have 53 values

What alternatives have you considered?

an anum, writing the values manually

Dominant language
TypeScript
Stars
16.7k
Forks
808
Avg merge
10h 38m
Merged PRs (30d)
495

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Effect-TS/effect

All issues in Effect-TS/effect

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.