lodash#snakeCase JavaScript Examples
The following examples show how to use
lodash#snakeCase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: requests.js From holo-schedule with MIT License | 6 votes |
async function* pagedItemsFetcher(endpoint, params = {}, paramEntries = []) {
const safeParams = mapKeys(params, (_, key) => snakeCase(key))
const { limit = 50 } = safeParams
const searchParams = new URLSearchParams({ limit, ...safeParams })
paramEntries.forEach(entry => searchParams.append(...entry))
let page = 0
let shouldContinue = true
do {
page += 1
searchParams.set('page', page.toString())
const { [endpoint.split('/')[0]]: items } = await fetchData(
`${TARGET}api/v1/${endpoint}?${searchParams.toString()}`,
)
yield items
if (items.length < limit) {
shouldContinue = false
}
} while (shouldContinue)
}
Example #2
Source File: transformKeys.jsx From ResoBin with MIT License | 6 votes |
snakeizeKeys = (obj) => {
if (Array.isArray(obj)) {
return obj.map((v) => snakeizeKeys(v))
}
if (obj instanceof Object) {
return Object.keys(obj).reduce(
(result, key) => ({
...result,
[snakeCase(key)]: snakeizeKeys(obj[key]),
}),
{}
)
}
return obj
}
Example #3
Source File: index.js From strapi-plugins with MIT License | 4 votes |
LeftMenuLinkContainer = ({ plugins }) => {
const location = useLocation();
// -- add this role variable --
const role = get(auth.getUserInfo(), 'role') || 'admin';
// -- --- --
// Generate the list of content types sections
const contentTypesSections = Object.keys(plugins).reduce((acc, current) => {
plugins[current].leftMenuSections.forEach((section = {}) => {
if (!isEmpty(section.links)) {
acc[snakeCase(section.name)] = {
name: section.name,
searchable: true,
links: get(acc[snakeCase(section.name)], 'links', []).concat(
section.links
.filter(link => link.isDisplayed !== false)
.map(link => {
link.plugin = !isEmpty(plugins[link.plugin]) ? link.plugin : plugins[current].id;
return link;
})
),
};
}
});
return acc;
}, {});
// Generate the list of plugin links (plugins without a mainComponent should not appear in the left menu)
const pluginsLinks = Object.values(plugins)
.filter(
plugin => plugin.id !== 'email' && plugin.id !== 'content-manager' && !!plugin.mainComponent
)
.map(plugin => {
const pluginSuffixUrl = plugin.suffixUrl ? plugin.suffixUrl(plugins) : '';
return {
icon: get(plugin, 'icon') || 'plug',
label: get(plugin, 'name'),
destination: `/plugins/${get(plugin, 'id')}${pluginSuffixUrl}`,
};
});
const menu = {
...contentTypesSections,
};
// -- add this role condition
if (role === 'admin') {
menu.plugins = {
searchable: false,
name: 'plugins',
emptyLinksListMessage: messages.noPluginsInstalled.id,
links: pluginsLinks,
};
menu.general = {
searchable: false,
name: 'general',
links: [
{
icon: 'list',
label: messages.listPlugins.id,
destination: '/list-plugins',
},
{
icon: 'shopping-basket',
label: messages.installNewPlugin.id,
destination: '/marketplace',
},
{
icon: 'cog',
label: messages.settings.id,
destination: SETTINGS_BASE_URL,
},
],
};
}
// -- --- --
return (
<Wrapper>
{Object.keys(menu).map(current => (
<LeftMenuLinkSection
key={current}
links={menu[current].links}
section={current}
location={location}
searchable={menu[current].searchable}
emptyLinksListMessage={menu[current].emptyLinksListMessage}
/>
))}
</Wrapper>
);
}