Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import decamelize from 'decamelize';
const a: string = decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
const b: string = decamelize('unicornRainbow', '-');
//=> 'unicorn-rainbow'
// $ExpectError
decamelize(42);
// $ExpectError
(decamelize('unicornRainbow'): number);
import decamelize from 'decamelize';
const a: string = decamelize('unicornRainbow');
//=> 'unicorn_rainbow'
const b: string = decamelize('unicornRainbow', '-');
//=> 'unicorn-rainbow'
// $ExpectError
decamelize(42);
// $ExpectError
(decamelize('unicornRainbow'): number);
function parseName(name) {
if (name.indexOf('_') !== -1) {
const pairs = name.split('_');
const component = pairs.shift();
return {
component: `${decamelize(component, '-')}`,
lang: pairs.join('-')
};
}
return {
component: `${decamelize(name, '-')}`,
lang: ''
};
}
function parseName(name) {
if (name.indexOf('_') !== -1) {
const pairs = name.split('_');
const component = pairs.shift();
return {
component: `${decamelize(component, '-')}`,
lang: pairs.join('-')
};
}
return {
component: `${decamelize(name, '-')}`,
lang: ''
};
}
export async function before(context) {
const { extJson, name, extensionScope } = context;
const pages = getOrSet(extJson, 'pages', []);
if (!_.every(pages, isHtmlPage)) {
throw new Error("Html pages can't be mixed with non-html settings pages in the same extension");
}
if (_.find(pages, { name })) {
throw new Error(`Page ${name} already exists`);
}
const pageName = name;
const pageDirectoryName = decamelize(name, '-');
_.merge(context, { pageName, pageDirectoryName });
pages.push({
name: pageName,
path: `server/pages/${pageDirectoryName}/index.html`,
type: 'html'
});
if (extensionScope) {
await instantiateExtensionTemplate('settings-page-html-extension', context)
} else {
await instantiateExtensionTemplate('settings-page-html-shortcut', context);
}
}
names.forEach(name => {
const component = decamelize(name, '-');
if (langs.length) {
langs.forEach(lang => {
routes.push({
name: `${lang}/${component}`,
path: `/${lang}/${component}`,
component: demos[name],
meta: {
name,
lang
}
});
});
} else {
routes.push({
name,
{Object.keys(pack.icons).map((iconName, index) => {
let Icon = pack.icons[iconName];
let realIconName = decamelize(iconName.replace(new RegExp('^'+prefixUp), ''), '-')
return (
<div>
<div>{iconName}</div>
<div style="{{fontSize:">
<code>{`react-icons/lib/${prefix}/${realIconName}`}</code>
</div>
</div>
);
})}
const parts = Object.keys(partsToDB).map((k) => ({
value: k,
label: capitalize.words(decamelize(k, ' '))
}))
default: ({ name }) => _.upperFirst(decamelize(name, ' ')),
message: 'Settings page title:',
function partialFinder(markdownBody) {
const regexToFindPartials = /<\w+ ?\/>/g;
const partials = markdownBody.match(regexToFindPartials);
if (partials) {
for (const partial of partials) {
const filename = decamelize(partial, "-").replace("<", "")
.replace("/>", "")
.trim();
const fileExistsTest = exists(`./app/components/${filename}.js`);
if (!fileExistsTest)
markdownBody = markdownBody.replace(partial, "");
else {
const partialFunction = require(path.join(__dirname, "..", `./components/${filename}.js`));
if (filename === "glossary-toc") markdownBody = markdownBody.replace(partial, partialFunction.default);
else markdownBody = markdownBody.replace(partial, `${partialFunction.default()}<div class="page__markup">`);
}
}
}
</div>