MCPcopy Create free account
hub / github.com/Keyang/node-csvtojson / dynamicType

Function dynamicType

v2/lineToJson.js:173–190  ·  view source on GitHub ↗
(item)

Source from the content-addressed store, hash-verified

171 return item.toString();
172}
173function dynamicType(item) {
174 var trimed = item.trim();
175 if (trimed === "") {
176 return stringType(item);
177 }
178 if (numReg.test(trimed)) {
179 return numberType(item);
180 }
181 else if (trimed.length === 5 && trimed.toLowerCase() === "false" || trimed.length === 4 && trimed.toLowerCase() === "true") {
182 return booleanType(item);
183 }
184 else if (trimed[0] === "{" && trimed[trimed.length - 1] === "}" || trimed[0] === "[" && trimed[trimed.length - 1] === "]") {
185 return jsonType(item);
186 }
187 else {
188 return stringType(item);
189 }
190}
191function booleanType(item) {
192 var trimmed = item.trim();
193 return !(trimmed.length === 5 && trimmed.toLowerCase() === "false");

Callers

nothing calls this directly

Calls 4

stringTypeFunction · 0.70
numberTypeFunction · 0.70
booleanTypeFunction · 0.70
jsonTypeFunction · 0.70

Tested by

no test coverage detected