MCPcopy Create free account
hub / github.com/denoland/std / #doGetTypeOfArray

Method #doGetTypeOfArray

toml/stringify.ts:116–134  ·  view source on GitHub ↗
(arr: unknown[])

Source from the content-addressed store, hash-verified

114 return type;
115 }
116 #doGetTypeOfArray(arr: unknown[]): ArrayType {
117 if (!arr.length) {
118 // any type should be fine
119 return "ONLY_PRIMITIVE";
120 }
121
122 const onlyPrimitive = this.#isPrimitive(arr[0]);
123 if (arr[0] instanceof Array) {
124 return "MIXED";
125 }
126 for (let i = 1; i < arr.length; i++) {
127 if (
128 onlyPrimitive !== this.#isPrimitive(arr[i]) || arr[i] instanceof Array
129 ) {
130 return "MIXED";
131 }
132 }
133 return onlyPrimitive ? "ONLY_PRIMITIVE" : "ONLY_OBJECT_EXCLUDING_ARRAY";
134 }
135 #printAsInlineValue(value: unknown): string | number {
136 if (value instanceof Date) {
137 return `"${this.#printDate(value)}"`;

Callers 1

#getTypeOfArrayMethod · 0.95

Calls 1

#isPrimitiveMethod · 0.95

Tested by

no test coverage detected