How to use the @teleporthq/teleport-shared.StringUtils.encode 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
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:
      throw new Error(
        `generateElementNode could not generate code for attribute of type ${JSON.stringify(
          attrValue
        )}`
      )
  }
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-common / src / utils / ast-utils.ts View on Github external
const getProperAttributeValueAssignment = (value: any, t = types) => {
  if (!value) {
    return null
  }

  if (typeof value === 'string') {
    return t.stringLiteral(StringUtils.encode(value))
  }

  return t.jsxExpressionContainer(convertValueToLiteral(value))
}
github teleporthq / teleport-code-generators / packages / teleport-plugin-common / src / node-handlers / node-to-jsx / index.ts View on Github external
const generateNode: NodeToJSX = (node, params, options) => {
  switch (node.type) {
    case 'static':
      return StringUtils.encode(node.content.toString())

    case 'dynamic':
      return createDynamicValueExpression(node, options)

    case 'element':
      return generateElementNode(node, params, options)

    case 'repeat':
      return generateRepeatNode(node, params, options)

    case 'conditional':
      return generateConditionalNode(node, params, options)

    case 'slot':
      if (options.slotHandling === 'native') {
        return generateNativeSlotNode(node, params, options)
github teleporthq / teleport-code-generators / packages / teleport-plugin-common / src / node-handlers / node-to-html / index.ts View on Github external
const generateNode: NodeToHTML = (node, params, templateSyntax) => {
  switch (node.type) {
    case 'static':
      return StringUtils.encode(node.content.toString())

    case 'dynamic':
      return templateSyntax.interpolation(node.content.id)

    case 'element':
      return generateElementNode(node, params, templateSyntax)

    case 'repeat':
      return generateRepeatNode(node, params, templateSyntax)

    case 'conditional':
      return generateConditionalNode(node, params, templateSyntax)

    case 'slot':
      return generateSlotNode(node, params, templateSyntax)