How to use the @uform/types.isObj function in @uform/types

To help you get started, we’ve selected a few @uform/types 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 alibaba / uform / packages / utils / src / accessor.ts View on Github external
if (!isObj(obj) || !path) {
    return
  }

  path = toString(path)

  if (path in obj) {
    obj[path as string] = value
    return
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    const p = pathArr[i]
    if (!isObj(obj[p])) {
      if (obj[p] === undefined && value === undefined) {
        return
      }
      if (/^\d+$/.test(pathArr[i + 1 + ''])) {
        if (getSchema) {
          const schema = getSchema(pathArr.slice(0, i) as string[])

          if (!schema || schema.type === 'array') {
            obj[p] = []
          } else {
            obj[p] = {}
          }
        } else {
          obj[p] = []
        }
      } else {
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
function _existIn(obj: any, path: Path) {
  if (!isObj(obj) || !path) {
    return false
  }

  path = toString(path)

  if (path in obj) {
    return true
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    if (isObj(obj)) {
      if (!(pathArr[i] in obj)) {
        return false
      }

      obj = obj[pathArr[i]]
    } else {
      return false
    }
  }

  return true
}
export const getIn = resolveGetIn(_getIn)
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
function _getIn(obj: any, path: Path, value: any) {
  if (!isObj(obj) || !path) {
    return obj
  }

  path = toString(path)

  if (path in obj) {
    return obj[path as string]
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    if (!Object.prototype.propertyIsEnumerable.call(obj, pathArr[i])) {
      return value
    }
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
function _existIn(obj: any, path: Path) {
  if (!isObj(obj) || !path) {
    return false
  }

  path = toString(path)

  if (path in obj) {
    return true
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    if (isObj(obj)) {
      if (!(pathArr[i] in obj)) {
        return false
      }
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
function _deleteIn(obj: any, path: Path) {
  if (!isObj(obj) || !path) {
    return
  }

  path = toString(path)

  if (path in obj) {
    delete obj[path as string]
    return
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    const p = pathArr[i]

    if (i === pathArr.length - 1) {
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
for (let i = 0; i < pathArr.length; i++) {
    const p = pathArr[i]

    if (i === pathArr.length - 1) {
      if (isArr(obj)) {
        obj.splice(p as number, 1)
      } else {
        delete obj[p]
      }
      return
    }

    obj = obj[p]

    if (!isObj(obj)) {
      return
    }
  }
}
github alibaba / uform / packages / utils / src / accessor.ts View on Github external
function _setIn(
  obj: any,
  path: Path,
  value: any,
  getSchema?: (path: string[] | number[]) => any
) {
  if (!isObj(obj) || !path) {
    return
  }

  path = toString(path)

  if (path in obj) {
    obj[path as string] = value
    return
  }

  const pathArr = getPathSegments(path)

  for (let i = 0; i < pathArr.length; i++) {
    const p = pathArr[i]
    if (!isObj(obj[p])) {
      if (obj[p] === undefined && value === undefined) {

@uform/types

> UForm数据校验工具

MIT
Latest version published 5 years ago

Package Health Score

68 / 100
Full package analysis

Similar packages