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

feat(useMath): new function #1841

Closed
wants to merge 1 commit into from
Closed

Conversation

FrankFang
Copy link
Contributor

Description

import { useMath } from '@vueuse/math'

const value = ref(45.95)
const rounded = useMath('round', value)
// rounded.value is 46
const floored = useMath('floor', value)
// floored.value is 45

Additional context

#1812


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@zojize
Copy link
Contributor

zojize commented Jul 12, 2022

ideally, I'd love to use this function like this:

const {
  ceiled, // 43
  floored, // 42
  // better names?
  absed, // 42.42
  sqrted, // 6.513063795173513
  sign, // 1
} = useMath(42.42)

@antfu
Copy link
Member

antfu commented Jul 12, 2022

For reference: https://github.com/vueuse/vue-chemistry#usage

@FrankFang
Copy link
Contributor Author

#1844 is better. close pr.

@FrankFang FrankFang closed this Jul 12, 2022
@FrankFang
Copy link
Contributor Author

FrankFang commented Jul 12, 2022

@zojize It looks good, But it's a little strange that the props of result depends on the number of params:

const {floored} = useMath(1.1) // no powed
const {powed} = useMath(2, 2) // no floored

@zojize
Copy link
Contributor

zojize commented Jul 12, 2022

@zojize It looks good, But it's a little strange that the props of result depends on the number of params:

const {floored} = useMath(1.1) // no powed
const {powed} = useMath(2, 2) // no floored

IMO in case of multiple arguments, it should be returned as a function.

e.g.

const { pow } = useMath(3)
const squared = pow(2) // ref(9)
const cubed = pow(3) // ref(27)

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

Successfully merging this pull request may close these issues.

None yet

3 participants