Skip to content

Commit

Permalink
feat(ui): Expose "is" utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Sep 13, 2022
1 parent 1352808 commit 76a9329
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 26 deletions.
4 changes: 4 additions & 0 deletions docs/src/assets/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,10 @@
"name": "Scrolling Utils",
"path": "scrolling-utils"
},
{
"name": "Type Checking Utils (<is>)",
"path": "type-checking-utils"
},
{
"name": "Other Utils",
"path": "other-utils"
Expand Down
59 changes: 59 additions & 0 deletions docs/src/pages/quasar-utils/type-checking-utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Type Checking Utils (<is>)
desc: A set of Quasar methods for type checking.
keys: is.deepEqual,is.object,is.date,is.regexp,is.number
badge: v2.8+
---

::: tip
For usage with the UMD build see [here](/start/umd#quasar-global-object).
:::

## is.deepEqual

Recursively checks if one Object is equal to another. Also supports Map, Set, ArrayBuffer, Regexp, Date, and many more.

```js
import { is } from 'quasar'

const objA = { /* ... */ }
const objB = { /* ... */ }

console.log( is.deepEqual(objA, objB) ) // true or false
```

## is.object

```js
import { is } from 'quasar'

const obj = { some: 'value' }
console.log( is.object(objA) ) // true or false
```

## is.date

```js
import { is } from 'quasar'

const myDate = new Date()
console.log( is.date(myDate) ) // true or false
```

## is.regexp

```js
import { is } from 'quasar'

const myRegexp = new Regexp(/* ... */)
console.log( is.date(myRegexp) ) // true or false
```

## is.number

```js
import { is } from 'quasar'

const myNumber = 80
console.log( is.date(myNumber) ) // true or false
```
1 change: 1 addition & 0 deletions docs/src/pages/start/umd.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Quasar.QBtn
Quasar.getCssVar('primary')
Quasar.debounce(fn, 200)
Quasar.Notify.create('Hi and welcome!')
Quasar.utils.is.deepEqual(objA, objB)
```

## Quasar Config Object
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/carousel/QCarousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import usePanel, { usePanelProps, usePanelEmits } from '../../composables/privat
import useFullscreen, { useFullscreenProps, useFullscreenEmits } from '../../composables/private/use-fullscreen.js'

import { createComponent } from '../../utils/private/create.js'
import { isNumber } from '../../utils/private/is.js'
import { isNumber } from '../../utils/is.js'
import { hMergeSlot, hDir } from '../../utils/private/render.js'

const navigationPositionOptions = [ 'top', 'right', 'bottom', 'left' ]
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/date/QDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { hSlot } from '../../utils/private/render.js'
import { formatDate, __splitDate, getDateDiff } from '../../utils/date.js'
import { pad } from '../../utils/format.js'
import { jalaaliMonthLength, toGregorian } from '../../utils/private/date-persian.js'
import { isObject } from '../../utils/private/is.js'
import { isObject } from '../../utils/is.js'

const yearsInterval = 20
const views = [ 'Calendar', 'Years', 'Months' ]
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/dialog-plugin/DialogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createComponent } from '../../utils/private/create.js'
import useDark, { useDarkProps } from '../../composables/private/use-dark.js'

import { isKeyCode } from '../../utils/private/key-composition.js'
import { isObject } from '../../utils/private/is.js'
import { isObject } from '../../utils/is.js'

export default createComponent({
name: 'DialogPlugin',
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/popup-edit/QPopupEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import QBtn from '../btn/QBtn.js'

import { createComponent } from '../../utils/private/create.js'
import clone from '../../utils/clone.js'
import { isDeepEqual } from '../../utils/private/is.js'
import { isDeepEqual } from '../../utils/is.js'
import { injectProp } from '../../utils/private/inject-obj-prop.js'

export default createComponent({
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/select/QSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useFormProps, useFormInputNameAttr } from '../../composables/private/us
import useKeyComposition from '../../composables/private/use-key-composition.js'

import { createComponent } from '../../utils/private/create.js'
import { isDeepEqual } from '../../utils/private/is.js'
import { isDeepEqual } from '../../utils/is.js'
import { stop, prevent, stopAndPrevent } from '../../utils/event.js'
import { normalizeToInterval } from '../../utils/format.js'
import { shouldIgnoreKey, isKeyCode } from '../../utils/private/key-composition.js'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/slider/use-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useFormProps, useFormInject } from '../../composables/private/use-form.

import { between } from '../../utils/format.js'
import { position } from '../../utils/event.js'
import { isNumber, isObject } from '../../utils/private/is.js'
import { isNumber, isObject } from '../../utils/is.js'
import { hDir } from '../../utils/private/render.js'

const markerPrefixClass = 'q-slider__marker-labels'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/table/table-column-selection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed } from 'vue'

import { isNumber } from '../../utils/private/is.js'
import { isNumber } from '../../utils/is.js'

export const useTableColumnSelectionProps = {
visibleColumns: Array
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/table/table-sort.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed } from 'vue'

import { sortDate } from '../../utils/private/sort.js'
import { isNumber, isDate, isObject } from '../../utils/private/is.js'
import { isNumber, isDate, isObject } from '../../utils/is.js'

export const useTableSortProps = {
sortMethod: Function,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/directives/Intersection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createDirective } from '../utils/private/create.js'
import { isDeepEqual } from '../utils/private/is.js'
import { isDeepEqual } from '../utils/is.js'
import getSSRProps from '../utils/private/noop-ssr-directive-transform.js'

const defaultCfg = {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/install-quasar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import IconSet from './icon-set.js'

import { quasarKey } from './utils/private/symbols.js'
import { globalConfig, globalConfigIsFrozen, freezeGlobalConfig } from './utils/private/global-config.js'
import { isObject } from './utils/private/is.js'
import { isObject } from './utils/is.js'

const autoInstalledPlugins = [
Platform,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/plugins/Loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import QSpinner from '../components/spinner/QSpinner.js'
import defineReactivePlugin from '../utils/private/define-reactive-plugin.js'
import { createGlobalNode, removeGlobalNode } from '../utils/private/global-nodes.js'
import preventScroll from '../utils/prevent-scroll.js'
import { isObject } from '../utils/private/is.js'
import { isObject } from '../utils/is.js'

let
app,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/plugins/LoadingBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createGlobalNode } from '../utils/private/global-nodes.js'
import { createChildApp } from '../install-quasar.js'

import QAjaxBar from '../components/ajax-bar/QAjaxBar.js'
import { isObject } from '../utils/private/is.js'
import { isObject } from '../utils/is.js'

const barRef = ref(null)

Expand Down
2 changes: 1 addition & 1 deletion ui/src/plugins/Notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createComponent } from '../utils/private/create.js'
import { noop } from '../utils/event.js'
import { createGlobalNode } from '../utils/private/global-nodes.js'
import { createChildApp } from '../install-quasar.js'
import { isObject } from '../utils/private/is.js'
import { isObject } from '../utils/is.js'

let uid = 0

Expand Down
2 changes: 2 additions & 0 deletions ui/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import extend from './utils/extend.js'
import format from './utils/format.js'
import frameDebounce from './utils/frame-debounce.js'
import getCssVar from './utils/get-css-var.js'
import is from './utils/is.js'
import morph from './utils/morph.js'
import openURL from './utils/open-url.js'
import patterns from './utils/patterns.js'
Expand All @@ -36,6 +37,7 @@ export {
frameDebounce,
getCssVar,
noop,
is,
morph,
openURL,
patterns,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/create-uploader-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { coreProps, coreEmits, getRenderer } from '../components/uploader/upload

import { createComponent } from './private/create.js'
import getEmitsObject from './private/get-emits-object.js'
import { isObject } from './private/is.js'
import { isObject } from './is.js'

const coreEmitsObject = getEmitsObject(coreEmits)

Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/date.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-fallthrough: 0 */

import { isDate } from './private/is.js'
import { isDate } from './is.js'
import { pad, capitalize } from './format.js'
import { jalaaliMonthLength } from './private/date-persian.js'
import lang, { defaultLang } from '../lang.js'
Expand Down
18 changes: 11 additions & 7 deletions ui/src/utils/private/is.js → ui/src/utils/is.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const
hasMap = typeof Map === 'function',
hasSet = typeof Set === 'function',
hasArrayBuffer = typeof ArrayBuffer === 'function'

export function isDeepEqual (a, b) {
if (a === b) {
Expand Down Expand Up @@ -31,7 +27,7 @@ export function isDeepEqual (a, b) {
return true
}

if (hasMap === true && a.constructor === Map) {
if (a.constructor === Map) {
if (a.size !== b.size) {
return false
}
Expand All @@ -55,7 +51,7 @@ export function isDeepEqual (a, b) {
return true
}

if (hasSet === true && a.constructor === Set) {
if (a.constructor === Set) {
if (a.size !== b.size) {
return false
}
Expand All @@ -71,7 +67,7 @@ export function isDeepEqual (a, b) {
return true
}

if (hasArrayBuffer === true && a.buffer != null && a.buffer.constructor === ArrayBuffer) {
if (a.buffer != null && a.buffer.constructor === ArrayBuffer) {
length = a.length

if (length !== b.length) {
Expand Down Expand Up @@ -137,3 +133,11 @@ export function isRegexp (v) {
export function isNumber (v) {
return typeof v === 'number' && isFinite(v)
}

export default {
deepEqual: isDeepEqual,
object: isObject,
date: isDate,
regexp: isRegexp,
number: isNumber
}
2 changes: 1 addition & 1 deletion ui/src/utils/morph.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject } from './private/is'
import { isObject } from './is'

let id = 0
let offsetBase = void 0
Expand Down
5 changes: 3 additions & 2 deletions ui/src/utils/open-url.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Platform from '../plugins/Platform.js'

import { noop } from './event.js'
import { isNumber } from './private/is.js'
import { isNumber } from './is.js'

function parseFeatures (winFeatures) {
const cfg = Object.assign({ noopener: true }, winFeatures)
Expand All @@ -10,7 +10,8 @@ function parseFeatures (winFeatures) {
const value = cfg[ key ]
if (value === true) {
feat.push(key)
} else if (isNumber(value) || (typeof value === 'string' && value !== '')) {
}
else if (isNumber(value) || (typeof value === 'string' && value !== '')) {
feat.push(key + '=' + value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/utils/private/web-storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noop } from '../event.js'
import { isDate, isRegexp } from './is.js'
import { isDate, isRegexp } from '../is.js'

function encode (value) {
if (isDate(value) === true) {
Expand Down

0 comments on commit 76a9329

Please sign in to comment.