processing / processing/p5.js

`nf` seems to have wrong prototypes

Open
#6,994 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Utilities Bug
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
p5.js version

main branch

Web browser and version

No response

Operating system

No response

Steps to reproduce this

This is generally a report about the documentation and test cases.

From the reference, the prototypes for nf are:

  • nf(num, [left], [right])
  • nf(nums, [left], [right])

However, from the source code, especially in doNf(num, left, right), there isn't check of type left === 'undefined', nor a default value for left, so when calling leftPart = leftPart.padStart(left, '0'), left cannot be undefined.

Also in the test suite of p5.prototype.nf, test cases are missing:

  • result = nf(1234), if left is optional
  • result = nf([1234, 3.141516, 3.141516e-2], 2) for an array of numbers to format

Contributor guide

Open the contributing guide

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.

Research direction

Start at doNf(num, left, right) and the p5.prototype.nf test suite, then compare their behavior with the documented nf prototypes in the reference. Check the optional-left and array-formatting cases described in the issue. Done means the implementation, tests, and reference documentation agree on supported arguments and behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.