Skip to content

Instantly share code, notes, and snippets.

@pyramation
Created May 12, 2021 04:22
Show Gist options
  • Save pyramation/1e3e29091284a52bf0b10a966939e04b to your computer and use it in GitHub Desktop.
Save pyramation/1e3e29091284a52bf0b10a966939e04b to your computer and use it in GitHub Desktop.
import * as React from "react";
import inflection from "inflection";
function getUnderscoreName(type) {
type = inflection.underscore(type).replace(/__/g, "_");
const parts = type.split("_");
let typ = [];
let needed = [];
for (let i = 0; i < parts.length; i++) {
if (parts[i].length === 1) {
needed.push(i);
} else {
typ.push(needed.map((j) => parts[j]).join(""));
needed = [];
typ.push(parts[i]);
}
}
typ.push(needed.map((j) => parts[j]).join(""));
typ = typ.filter(Boolean);
return typ.join("_");
}
export default function App() {
return (
<div className="App">{getUnderscoreName("GraphQLWebACLHelloWorld")}</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment