MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / stringFromUnknown

Function stringFromUnknown

src/lib/util.ts:1–22  ·  view source on GitHub ↗
(input: unknown)

Source from the content-addressed store, hash-verified

1export const stringFromUnknown = (input: unknown): string => {
2 if (typeof input === 'string') {
3 return input
4 }
5 if (input == undefined) {
6 return ''
7 }
8 if (typeof input === 'function') {
9 return '<Function>'
10 }
11 if (typeof input === 'number' || typeof input == 'boolean' || typeof input === 'bigint' ||
12 typeof input === 'symbol') {
13 return input.toString()
14 }
15 if (typeof input === 'object') {
16 // For object, only use the toString if it's not the default from `Object`.
17 if (input.toString !== Object.prototype.toString) {
18 return input.toString()
19 }
20 }
21 return JSON.stringify(input)
22}
23
24/**
25 * Clip the input string to the maximum length, using ellipses if it is too long.

Callers 4

getDisplayValueForFunction · 0.85
checkboxDefFunction · 0.85
selectDefFunction · 0.85
util.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected