Commit
•
9a79ad0
1
Parent(s):
9bf7dbb
🔥 Remove lodash from client code
Browse files
src/lib/utils/generateId.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
import { kebabCase } from 'lodash';
|
2 |
import { nanoid } from 'nanoid';
|
|
|
3 |
|
4 |
export function generateId(name: string): string {
|
5 |
return kebabCase(name.replace(/&/g, '-and-')) + '-' + nanoid(6);
|
|
|
|
|
1 |
import { nanoid } from 'nanoid';
|
2 |
+
import { kebabCase } from './kebabCase';
|
3 |
|
4 |
export function generateId(name: string): string {
|
5 |
return kebabCase(name.replace(/&/g, '-and-')) + '-' + nanoid(6);
|
src/lib/utils/kebabCase.ts
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export const kebabCase = (str: string): string =>
|
2 |
+
(str.match(/[A-Z]{2,}(?=[A-Z][a-z0-9]*|\b)|[A-Z]?[a-z0-9]*|[A-Z]|[0-9]+/g) ?? [])
|
3 |
+
.filter(Boolean)
|
4 |
+
.map((x) => x.toLowerCase())
|
5 |
+
.join('-');
|
src/routes/admin/produits/[id]/+page.server.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
import { client, collections
|
2 |
import type { Product } from '$lib/types/Product';
|
3 |
import { error, redirect } from '@sveltejs/kit';
|
4 |
import type { Actions, PageServerLoad } from './$types';
|
5 |
-
import { omit } from 'lodash';
|
6 |
|
7 |
export const load: PageServerLoad = async ({ params }) => {
|
8 |
const product = await collections.products.findOne({ _id: params.id });
|
|
|
1 |
+
import { client, collections } from '$lib/server/db';
|
2 |
import type { Product } from '$lib/types/Product';
|
3 |
import { error, redirect } from '@sveltejs/kit';
|
4 |
import type { Actions, PageServerLoad } from './$types';
|
|
|
5 |
|
6 |
export const load: PageServerLoad = async ({ params }) => {
|
7 |
const product = await collections.products.findOne({ _id: params.id });
|