_constructGradientValue.js.flow 849 B

1234567891011121314151617181920212223
  1. // @flow
  2. function constructGradientValue(literals: Array<string>, ...substitutions: Array<string>): string {
  3. let template = ''
  4. for (let i = 0; i < literals.length; i += 1) {
  5. template += literals[i]
  6. if (i === substitutions.length - 1 && substitutions[i]) {
  7. const definedValues = substitutions.filter(substitute => !!substitute)
  8. // Adds leading coma if properties preceed color-stops
  9. if (definedValues.length > 1) {
  10. template = template.slice(0, -1)
  11. template += `, ${substitutions[i]}`
  12. // No trailing space if color-stops is the only param provided
  13. } else if (definedValues.length === 1) {
  14. template += `${substitutions[i]}`
  15. }
  16. } else if (substitutions[i]) {
  17. template += `${substitutions[i]} `
  18. }
  19. }
  20. return template.trim()
  21. }
  22. export default constructGradientValue