feat(new-tool): slugify string

This commit is contained in:
Corentin Thomasset 2023-02-10 22:06:32 +01:00
parent 1a3f0a135d
commit 6fe4b5ac60
No known key found for this signature in database
GPG key ID: DBD997E935996158
5 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,11 @@
import { AbcRound } from '@vicons/material';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Slugify string',
path: '/slugify-string',
description: 'Make a string url, filename and id safe.',
keywords: ['slugify', 'string', 'escape', 'emoji', 'special', 'character', 'space', 'trim'],
component: () => import('./slugify-string.vue'),
icon: AbcRound,
});

View file

@ -0,0 +1,33 @@
<template>
<div>
<n-form-item label="Your string to slugify">
<n-input v-model:value="input" type="textarea" placeholder="Put your string here (ex: My file path)"></n-input>
</n-form-item>
<n-form-item label="Your slug">
<n-input
:value="slug"
type="textarea"
readonly
placeholder="You slug will be generated here (ex: my-file-path)"
></n-input>
</n-form-item>
<n-space justify="center">
<n-button secondary :disabled="slug.length === 0" @click="copy">Copy slug</n-button>
</n-space>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue';
import slugify from '@sindresorhus/slugify';
import { withDefaultOnError } from '@/utils/defaults';
import { useCopy } from '@/composable/copy';
const input = ref('');
const slug = computed(() => withDefaultOnError(() => slugify(input.value), ''));
const { copy } = useCopy({ source: slug, text: 'Slug copied to clipboard' });
</script>
<style lang="less" scoped></style>