How to use the @vue/shared.camelize function in @vue/shared

To help you get started, we’ve selected a few @vue/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / decorators / src / prop.ts View on Github external
function applyProp(target: any, key: string, options: PropValidator = {}) {
  // here `target` is the prototype of the component class
  Object.defineProperty(target, `__prop_${camelize(key)}`, {
    value: options
  })
}
github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
if (__DEV__ && !isString(raw[i])) {
        warn(`props must be strings when using array syntax.`, raw[i])
      }
      const normalizedKey = camelize(raw[i])
      if (normalizedKey[0] !== '$') {
        options[normalizedKey] = EMPTY_OBJ
      } else if (__DEV__) {
        warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
      }
    }
  } else {
    if (__DEV__ && !isObject(raw)) {
      warn(`invalid props options`, raw)
    }
    for (const key in raw) {
      const normalizedKey = camelize(key)
      if (normalizedKey[0] !== '$') {
        const opt = raw[key]
        const prop: NormalizedProp = (options[normalizedKey] =
          isArray(opt) || isFunction(opt) ? { type: opt } : opt)
        if (prop != null) {
          const booleanIndex = getTypeIndex(Boolean, prop.type)
          const stringIndex = getTypeIndex(String, prop.type)
          prop[BooleanFlags.shouldCast] = booleanIndex > -1
          prop[BooleanFlags.shouldCastTrue] = booleanIndex < stringIndex
          // if the prop needs boolean casting or default value
          if (booleanIndex > -1 || hasOwn(prop, 'default')) {
            needCastKeys.push(normalizedKey)
          }
        }
      } else if (__DEV__) {
        warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
github vuejs / vue-next / packages / compiler-core / src / transforms / vBind.ts View on Github external
export const transformBind: DirectiveTransform = (dir, node, context) => {
  const { exp, modifiers, loc } = dir
  const arg = dir.arg!
  if (!exp) {
    context.onError(createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc))
  }
  // .prop is no longer necessary due to new patch behavior
  // .sync is replaced by v-model:arg
  if (modifiers.includes('camel')) {
    if (arg.type === NodeTypes.SIMPLE_EXPRESSION) {
      if (arg.isStatic) {
        arg.content = camelize(arg.content)
      } else {
        arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`
      }
    } else {
      arg.children.unshift(`${context.helperString(CAMELIZE)}(`)
      arg.children.push(`)`)
    }
  }
  return {
    props: [
      createObjectProperty(arg!, exp || createSimpleExpression('', true, loc))
    ],
    needRuntime: false
  }
}
github vuejs / vue-next / packages / runtime-core / src / helpers / resolveAssets.ts View on Github external
function resolveAsset(
  type: typeof COMPONENTS | typeof DIRECTIVES,
  name: string,
  instance: ComponentInternalInstance | null = currentRenderingInstance ||
    currentInstance
) {
  if (instance) {
    let camelized, capitalized
    const registry = instance[type]
    let res =
      registry[name] ||
      registry[(camelized = camelize(name))] ||
      registry[(capitalized = capitalize(camelized))]
    if (!res && type === COMPONENTS) {
      const self = instance.type
      const selfName = (self as FunctionalComponent).displayName || self.name
      if (
        selfName &&
        (selfName === name ||
          selfName === camelized ||
          selfName === capitalized)
      ) {
        res = self
      }
    }
    if (__DEV__ && !res) {
      warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`)
    }
github vuejs / vue-next / packages / runtime-core / src / componentProps.ts View on Github external
if (__DEV__ && !isString(raw[i])) {
        warn(`props must be strings when using array syntax.`, raw[i])
      }
      const normalizedKey = camelize(raw[i])
      if (!isReservedKey(normalizedKey)) {
        normalized[normalizedKey] = EMPTY_OBJ
      } else if (__DEV__) {
        warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
      }
    }
  } else {
    if (__DEV__ && !isObject(raw)) {
      warn(`invalid props options`, raw)
    }
    for (const key in raw) {
      const normalizedKey = camelize(key)
      if (!isReservedKey(normalizedKey)) {
        const opt = raw[key]
        const prop = (normalized[normalizedKey] =
          isArray(opt) || isFunction(opt) ? { type: opt } : opt)
        if (prop) {
          const booleanIndex = getTypeIndex(Boolean, prop.type)
          const stringIndex = getTypeIndex(String, prop.type)
          ;(prop as NormalizedProp)[BooleanFlags.shouldCast] = booleanIndex > -1
          ;(prop as NormalizedProp)[BooleanFlags.shouldCastTrue] =
            booleanIndex < stringIndex
        }
      } else if (__DEV__) {
        warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
      }
    }
  }