src/parts.js
function resolveAttributeValue(value, part) {
  if (isDirective(value)) {
    value = resolveDirectiveValue(value, part);
  }

  if (value === nothingString) {
    return value;
  }

  if (isTemplateResult(value)) {
    value = value.read();
  }

  if (isPrimitive(value)) {
    const string = typeof value !== 'string' ? String(value) : value;
    // Escape if not prefixed with unsafePrefixString, otherwise strip prefix
    return Buffer.from(
      string.indexOf(unsafePrefixString) === 0 ? string.slice(33) : escapeHTML(string)
    );
  } else if (Buffer.isBuffer(value)) {
    return value;
  } else if (isPromise(value)) {
    return value.then((value) => resolveAttributeValue(value, part));
  } else if (isSyncIterator(value)) {
    if (!Array.isArray(value)) {
      value = Array.from(value);
    }
    return Buffer.concat(
      value.reduce((values, value) => {
        value = resolveAttributeValue(value, part);
        // Flatten
        if (Array.isArray(value)) {
          return values.concat(value);
        }
        values.push(value);
        return values;
      }, [])
    );
  } else {
    throw Error('unknown AttributPart value', value);
  }
}
function resolveAttributeValue(value, part) {
  if (isDirective(value)) {
    value = resolveDirectiveValue(value, part);
  }

  if (value === nothingString) {
    return value;
  }

  if (isTemplateResult(value)) {
    value = value.read();
  }

  if (isPrimitive(value)) {
    const string = typeof value !== 'string' ? String(value) : value;
    // Escape if not prefixed with unsafePrefixString, otherwise strip prefix
    return Buffer.from(
      string.indexOf(unsafePrefixString) === 0 ? string.slice(33) : escapeHTML(string)
    );
  } else if (Buffer.isBuffer(value)) {
    return value;
  } else if (isPromise(value)) {
    return value.then((value) => resolveAttributeValue(value, part));
  } else if (isSyncIterator(value)) {
    if (!Array.isArray(value)) {
      value = Array.from(value);
    }
    return Buffer.concat(
      value.reduce((values, value) => {
        value = resolveAttributeValue(value, part);
        // Flatten
        if (Array.isArray(value)) {
          return values.concat(value);
        }
        values.push(value);
        return values;
      }, [])
    );
  } else {
    throw Error('unknown AttributPart value', value);
  }
}
function resolveAttributeValue ( value , part ) { if ( isDirective ( value ) ) { value = resolveDirectiveValue ( value , part ) ; } if ( value === nothingString ) { return value ; } if ( isTemplateResult ( value ) ) { value = value . read ( ) ; } if ( isPrimitive ( value ) ) { const string = typeof value !== 'string' ? String ( value ) : value ; // Escape if not prefixed with unsafePrefixString, otherwise strip prefix return Buffer . from ( string . indexOf ( unsafePrefixString ) === 0 ? string . slice ( 33 ) : escapeHTML ( string ) ) ; } else if ( Buffer . isBuffer ( value ) ) { return value ; } else if ( isPromise ( value ) ) { return value . then ( ( value ) => resolveAttributeValue ( value , part ) ) ; } else if ( isSyncIterator ( value ) ) { if ( ! Array . isArray ( value ) ) { value = Array . from ( value ) ; } return Buffer . concat ( value . reduce ( ( values , value ) => { value = resolveAttributeValue ( value , part ) ; // Flatten if ( Array . isArray ( value ) ) { return values . concat ( value ) ; } values . push ( value ) ; return values ; } , [ ] ) ) ; } else { throw Error ( 'unknown AttributPart value' , value ) ; } }
Resolve "value" to string if possible

@param { any } value
@param { AttributePart } part
@returns { any }
Resolve value to string if possible