How to use the @teleporthq/teleport-shared.StringUtils.capitalize function in @teleporthq/teleport-shared

To help you get started, we’ve selected a few @teleporthq/teleport-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 teleporthq / teleport-code-generators / packages / teleport-plugin-common / src / node-handlers / node-to-html / utils.ts View on Github external
attrValue: UIDLAttributeValue,
  params: HTMLTemplateGenerationParams,
  templateSyntax: HTMLTemplateSyntax,
  node: UIDLElementNode
) => {
  const { dataObject } = params
  const dynamicAttrKey = templateSyntax.valueBinding(attrKey, node)
  switch (attrValue.type) {
    case 'dynamic':
      hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, attrValue.content.id)
      break
    case 'static':
      if (Array.isArray(attrValue.content)) {
        // This handles the cases when arrays are sent as props or passed as attributes
        // The array will be placed on the dataObject and the data reference is placed on the node
        const dataObjectIdentifier = `${elementName}${StringUtils.capitalize(attrKey)}`
        dataObject[dataObjectIdentifier] = attrValue.content
        hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, dataObjectIdentifier)
      } else if (typeof attrValue.content === 'boolean') {
        hastUtils.addBooleanAttributeToNode(htmlNode, attrKey)
      } else if (typeof attrValue.content === 'string') {
        hastUtils.addAttributeToNode(
          htmlNode,
          attrKey,
          StringUtils.encode(attrValue.content.toString())
        )
      } else {
        // For numbers and values that are passed to components and maintain their type
        hastUtils.addAttributeToNode(htmlNode, dynamicAttrKey, attrValue.content.toString())
      }
      break
    default:
github teleporthq / teleport-code-generators / packages / teleport-plugin-common / src / node-handlers / node-to-jsx / utils.ts View on Github external
const stateKey = eventHandlerStatement.modifies
  const stateDefinition = stateDefinitions[stateKey]

  const statePrefix = options.dynamicReferencePrefixMap.state
    ? options.dynamicReferencePrefixMap.state + '.'
    : ''

  const newStateValue =
    eventHandlerStatement.newState === '$toggle'
      ? t.unaryExpression('!', t.identifier(statePrefix + stateKey))
      : convertValueToLiteral(eventHandlerStatement.newState, stateDefinition.type)

  switch (options.stateHandling) {
    case 'hooks':
      return t.expressionStatement(
        t.callExpression(t.identifier(`set${StringUtils.capitalize(stateKey)}`), [newStateValue])
      )
    case 'function':
      return t.expressionStatement(
        t.callExpression(t.identifier('this.setState'), [
          t.objectExpression([t.objectProperty(t.identifier(stateKey), newStateValue)]),
        ])
      )
    case 'mutation':
    default:
      return t.expressionStatement(
        t.assignmentExpression('=', t.identifier(statePrefix + stateKey), newStateValue)
      )
  }
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-react-base-component / src / utils.ts View on Github external
const createStateHookAST = (stateKey: string, stateDefinition: UIDLStateDefinition, t = types) => {
  const defaultValueArgument = ASTUtils.convertValueToLiteral(
    stateDefinition.defaultValue,
    stateDefinition.type
  )

  return t.variableDeclaration('const', [
    t.variableDeclarator(
      t.arrayPattern([
        t.identifier(stateKey),
        t.identifier(`set${StringUtils.capitalize(stateKey)}`),
      ]),
      t.callExpression(t.identifier('useState'), [defaultValueArgument])
    ),
  ])
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-export-components / src / index.ts View on Github external
exportSpecifiers = Object.keys(components).map((component) =>
      t.exportSpecifier(
        t.identifier(StringUtils.capitalize(component)),
        t.identifier(StringUtils.capitalize(component))
      )
    )