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(useCeil): new function #1818

Merged
merged 1 commit into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/math/useCeil/index.md
@@ -0,0 +1,16 @@
---
category: '@Math'
---

# useCeil

Reactively Math.ceil(value).

## Usage

```ts
import { useCeil } from '@vueuse/math'

const value = ref(0.95)
const result = useCeil(value)
```
15 changes: 15 additions & 0 deletions packages/math/useCeil/index.test.ts
@@ -0,0 +1,15 @@
import { ref } from 'vue-demi'
import { useCeil } from '.'

describe('useCeil', () => {
it('should be defined', () => {
expect(useCeil).toBeDefined()
})
it('should work', () => {
const base = ref(0.95)
const result = useCeil(base)
expect(result.value).toBe(1)
base.value = -7.004
expect(result.value).toBe(-7)
})
})
15 changes: 15 additions & 0 deletions packages/math/useCeil/index.ts
@@ -0,0 +1,15 @@
import type { ComputedRef } from 'vue-demi'
import { computed } from 'vue-demi'
import type { MaybeComputedRef } from '@vueuse/shared'
import { resolveUnref } from '@vueuse/shared'

/**
* Reactively Math.ceil(value).
*
* @see https://vueuse.org/useCeil
* @param base
* @param exponent
*/
export function useCeil(value: MaybeComputedRef<number>): ComputedRef<number> {
return computed<number>(() => Math.ceil(resolveUnref(value)))
}