Skip to content

Commit

Permalink
feat(useCeil): new function (#1818)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Jul 10, 2022
1 parent e300c06 commit 80461b4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
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)))
}

0 comments on commit 80461b4

Please sign in to comment.