MCPcopy
hub / github.com/serverless/serverless / stringToSafeColor

Function stringToSafeColor

packages/util/src/logger/index.js:171–185  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

169 * Useful for colorizing strings consistenyl based on their content.
170 */
171const stringToSafeColor = (str) => {
172 let hash = 0
173 for (let i = 0; i < str.length; i++) {
174 hash = str.charCodeAt(i) + ((hash << 5) - hash)
175 }
176
177 const base = 128
178 const range = 127
179
180 const red = base + (hash & range)
181 const green = base + ((hash >> 8) & range)
182 const blue = base + ((hash >> 16) & range)
183
184 return chalk.rgb(red, green, blue)
185}
186
187/**
188 * Colorize a string based on its "safe" color

Callers 2

connectMethod · 0.90
colorizeStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…