Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename *ify functions (DO NOT SQUASH) #110

Draft
wants to merge 8 commits into
base: next
Choose a base branch
from

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jul 14, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

  • Rename listify to mapEntriesToArray
  • Rename objectify to castObject
  • Rename mapify to castMap
  • Add src/transform folder + tests/docs/benchmarks folders
  • Move toInt into the “transform” folders.
  • Move toFloat into the “transform” folders.

Related issue, if any:

https://github.com/orgs/radashi-org/discussions/65

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

Yes

A codemod should be written for this change.

Bundle impact

Status File Size Difference (%)
R073 src/array/mapify.ts 0 -117 (-100%)
src/array/castMap.ts A 0 +0
src/array/castObject.ts D 0 +0
src/array/objectify.ts M 0 +0
src/object/crush.ts D 0 +0
src/object/listify.ts A 0 +0

@aleclarson aleclarson added the BREAKING CHANGE Not backwards compatible label Jul 14, 2024
@aleclarson aleclarson force-pushed the refactor/transforms branch from a925326 to 5aa6cc5 Compare July 14, 2024 19:53
@aleclarson
Copy link
Member Author

Decided to rename toObject (now castObject) and toMap (now castMap) as they didn't fit the naming convention below:

Naming guideline for conversion functions

  • The to* convention dictates that the function should accept value: any and it should always have one argument. Effectively, the to prefix is reserved for “value parsing” functions. Our toInt and toFloat functions fit this class well.
  • The cast* convention dictates that stricter parameter types and parameter count are allowed. Effectively, the cast prefix is a catch-all for any “non-destructive value transformation” task.
    • Casting functions are assumed to return a new object reference when an object return value is expected. For example, if castArray receives an array, it shallow copies it and returns the copy. This rule ensures the casted result is free to be mutated without “action at a distance”.

@aleclarson
Copy link
Member Author

aleclarson commented Jul 14, 2024

Also renamed toArray (now mapEntriesToArray). I believe this make it more discoverable, and it pairs well with mapEntries from a naming perspective.

Ultimately, the goal is to avoid casted and transform function groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE Not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant