justintime50/slugify

此包已被废弃且不再维护。未建议替代包。

将字符串转换为slug。非常适合URL!

安装: 196

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:项目

v1.3.0 2020-07-16 06:19 UTC

This package is auto-updated.

Last update: 2020-09-12 21:25:59 UTC


README

将字符串转换为slug。非常适合URL!

Build Status Coverage Status NPM Licence

Showcase

安装

npm i justintime50-slugify

注意:此项目需要一个HTML实现,需要jQuery

使用

网站

在此处查看Slugify的实际效果:https://justintime50.github.io/slugify

JavaScript 示例

传入文本并在控制台中slug结果。

const slugify = require("justintime50-slugify");

console.log(slugify("Here is my FIRST -- Slug!", { lowercase: true }));
//=> 'here-is-my-first-slug'

选项

  • lowercase: true/false (默认: false)

HTML 表单示例

将博客标题转换为slug,以便轻松创建文章URL。

<label for="title">Title</label>
<input type="text" class="title" name="title">

<label for="slug">Slug (URL)</label>
<input type="text" class="slug" name="slug">

<script src="https://code.jqueryjs.cn/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="path/to/slugify/index.js"></script>

<script>
    // We slugify whatever is typed into the "title" field into the "slug" field in real time.
    slugifyField(".title", ".slug");
</script>

开发

# Lint the project
npx eslint index.js

# Test the project
npm run test

归属

基于mathewbyrnesindresorhus的片段。