Skip to content

@stdlib/string: startcase function does not work when the input string is fully uppercase #491

@KBeDevel

Description

@KBeDevel

Description

Encountered an unexpected result when trying to change the case of an enumerator key

The string is obtained using the logic: Enumerator[Enumerator.EnumeratorKey]

Related Issues

No related issues found (yet)

Questions

No.

Demo

https://codesandbox.io/s/agitated-hill-v37msg?file=/src/App.tsx

Reproduction

- Define/import an enumerator with uppercase string keys
- Use the enumerator value to get the enumerator key (`startcase(Enumerator[Enumerator.ENUMERATOR_KEY])`)

Expected Results

Execute `startcase(StatusCodes[StatusCodes.UNAUTHORIZED])` and obtain `'Unauthorized'`

Actual Results

// The enumerator is exported by the `http-status-codes` library

enum StatusCodes { // Enumerator structure for reference
  ACCEPTED = 202,
  BAD_GATEWAY = 502,
  // ...
  UNAUTHORIZED = 401,
  // ...
};

startcase(StatusCodes[StatusCodes.UNAUTHORIZED]); // -> UNAUTHORIZED

startcase(StatusCodes[StatusCodes.UNAUTHORIZED].toString()) // -> UNAUTHORIZED

startcase(`${StatusCodes[StatusCodes.UNAUTHORIZED]}`); // -> UNAUTHORIZED

startcase("UNAUTHORIZED"); // -> UNAUTHORIZED

The workaround is:

startcase(StatusCodes[StatusCodes.UNAUTHORIZED].toLowerCase()); // -> Unauthorized

Version

"@stdlib/string": "^0.0.13"

Environments

Firefox, Chrome, Microsoft Edge

Browser Version

No response

Node.js / npm Version

[email protected] / [email protected] ([email protected])

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working.wont-fixUnable and/or unwilling to resolve concern due to inapplicability or lack of problem definition.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions