Coder Social home page Coder Social logo

inooid / node-simple-slugify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from up9cloud/node-simple-slugify

0.0 0.0 0.0 494 KB

Slugify a string, simply replace "Reserved characters", and "Unsafe characters" to "-"

License: MIT License

JavaScript 93.76% HTML 6.24%

node-simple-slugify's Introduction

simple-slugify

Build Status Coverage Status

Slugify a string, simply replace "Reserved characters", and "Unsafe characters" to "-".

Usage

const { slugify } = require('simple-slugify')

slugify('I ♥') // i-♥
slugify('大好き ♥', '_') // 大好き_♥
<!-- browser side -->
<script src="https://unpkg.com/simple-slugify/dist/simple-slugify.min.js"></script>
<script>
  console.log(simpleSlugify.slugify('I ♥')) // i-♥
</script>

Api

const {
  defaultOptions,
  slugify,
  Slugify
} = require('simple-slugify')

defaultOptions

console.log(defaultOptions)
// {
//   lowercase: true,
//   normalize: 'NFKC',
//   replacement: '-',
//   reserved: true,
//   unsafe: true,
//   trim: true,
//   spaceLess: true,
//   space: true
// }

See details at ./src/index.js const defaultOptions

slugify

slugify(source: string, [replacement: string | options: object]): string
slugify(' A?#  b ') // a---b
slugify(' A?#  b ', '_') // a___b
slugify(' A?#  b ', {
  lowercase: false,
  replacement: '_',
  trim: false,
  spaceLess: false,
  space: '-'
}) // -A__--b-

Slugify

const s = new Slugify

// memorize slug, make sure the returning slug is unique
s.slug(source: string, [replacement: string | options: object], [separator: string]): string

// clear memory
s.reset(): void
const { Slugify } = require('simple-slugify')
const s = new Slugify
s.slug('大好き ♥') // 大好き-♥
s.slug('大好き ♥') // 大好き-♥.1

s.reset()
s.slug('大好き ♥') // 大好き-♥
s.slug('大好き ♥', { space: false }, '_') // 大好き ♥
s.slug('大好き ♥', { space: false }, '_') // 大好き ♥_1
s.slug('大好き ♥_1', { space: false }, '_') // 大好き ♥_1_1
<!-- browser side -->
<script src="https://unpkg.com/simple-slugify/dist/simple-slugify.min.js"></script>
<script>
  var s = new simpleSlugify.Slugify()
  console.log(s.slug('I ♥')) // i-♥
  console.log(s.slug('I ♥')) // i-♥.1
</script>

Why

This lib focus on world wide human readable url, doesn't translate things to English. The non-english native people actually don't know too much English as programmers thought. So this lib converts characters only if necessary, only cover reserved, unsafe characters.

If you are looking for lib translating characters, please consider https://github.com/simov/slugify.

node-simple-slugify's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar up9cloud avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.