refactor: option merging + extract helper functions
This commit is contained in:
1
packages/shared/README.md
Normal file
1
packages/shared/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# @vue/shared
|
||||
4
packages/shared/package.json
Normal file
4
packages/shared/package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "@vue/shared",
|
||||
"private": true
|
||||
}
|
||||
29
packages/shared/src/index.ts
Normal file
29
packages/shared/src/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export const EMPTY_OBJ: { readonly [key: string]: any } = Object.freeze({})
|
||||
|
||||
export const NOOP = () => {}
|
||||
|
||||
export const onRE = /^on/
|
||||
export const vnodeHookRE = /^vnode/
|
||||
export const handlersRE = /^on|^vnode/
|
||||
export const reservedPropRE = /^(?:key|ref|slots)$|^vnode/
|
||||
|
||||
export const isArray = Array.isArray
|
||||
export const isFunction = (val: any): val is Function =>
|
||||
typeof val === 'function'
|
||||
export const isString = (val: any): val is string => typeof val === 'string'
|
||||
export const isObject = (val: any): val is Record<any, any> =>
|
||||
val !== null && typeof val === 'object'
|
||||
|
||||
const camelizeRE = /-(\w)/g
|
||||
export const camelize = (str: string): string => {
|
||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
|
||||
}
|
||||
|
||||
const hyphenateRE = /\B([A-Z])/g
|
||||
export const hyphenate = (str: string): string => {
|
||||
return str.replace(hyphenateRE, '-$1').toLowerCase()
|
||||
}
|
||||
|
||||
export const capitalize = (str: string): string => {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1)
|
||||
}
|
||||
Reference in New Issue
Block a user