speakingurl-add-korean

1.1.0 • Public • Published

SpeakingURL NPM version Build Status Gitter

Generate a slug with a lot of options; create of so called 'static' or 'Clean URL' or 'Pretty URL' or 'nice-looking URL' or 'Speaking URL' or 'user-friendly URL' or 'SEO-friendly URL' from a string. This module aims to transliterate the input string.

For use in browser and server - no dependencies!

Notes

Never use the slug to reference to the unique page in the database – if the title will change, you want to change the slug – you run into problems.

  1. Use a unique reference to the record – e.g. a unique key "12345" => /my-little-title-12345.html
  2. Store all historical slugs in the page record; but you have to re-calculate the slug from all pages – every time you update speakingurl

Redirect with 301 to the last/current slug.

NPM Badge

Module Status

Installation

npm

npm install speakingurl-add-korean --save

Bower

bower install --save speakingurl-add-korean

Download Package

copy the file speakingurl.min.js to your script directory

CDN/cloudflare

CDN/maxcdn

Usage

getSlug(input, [options]);

input: {string} to convert

options {object|string} config object or separator string (see below)

  • options {object}

    • separator {string} default: '-'
      • char that replace the whitespaces
    • lang {string} default: 'en'
      • false -> don't convert symbols
      • language for symbol translation ('ar', 'cz', 'de', 'en', 'es', 'fr', 'hu', 'it', 'my, 'nl', pt', 'ru', 'sk', 'tr' and 'vn'; more coming soon, please help!)
      • false -> don't convert symbols
    • maintainCase {boolean} default: false
      • true -> maintain case chars
      • false -> convert all chars to lower case
    • titleCase {boolean|array} default: false
      • true -> convert input string to title-case
      • array -> titlecase = true, but omit the words from in the array
    • truncate {number} default: 0
      • 0 -> don't trim length
      • >= 1 -> trim to max length while not breaking any words
    • uric {boolean} default: false
      • true -> additionally allow chars: ";", "?", ":", "@", "&", "=", "+", "$", ",", "/"
      • false
    • uricNoSlash {boolean} default: false
      • true -> additionally allow chars: ";", "?", ":", "@", "&", "=", "+", "$", ","
    • mark {boolean} default: false
      • true -> additionally allow chars: "-", "_", ".", "!", "~", "*", "'", "(", ")"
    • custom {object|array} default: {}
      • object -> custom map for translation, overwrites all i.e. { '&': '#', '*': ' star ' }
      • array -> add chars to allowed charMap (see example)
  • options {string} separator

notes: default only Base64 chars are allowed (/A-Za-z0-9_-/), setting uric, uricNoSlash or/and mark to true will add the specified chars to the list of allowed characters. The separator-character is always allowed.

Node.js
var getSlug = require('speakingurl');
Browser
<script src="bower_components/speakingurl/speakingurl.min.js"></script>

Examples

var slug;
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !");
console.log(slug); // Output: schoener-titel-laesst-gruessen-bel-ete
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", '*');
console.log(slug); // Output: schoener*titel*laesst*gruessen*bel*ete
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
        separator: '_'
    });
console.log(slug); // Output: schoener_titel_laesst_gruessen_bel_ete
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
        uric: true
    });
console.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
     uricNoSlash: true
    });
console.log(slug); // Output: schoener-titel-laesst-gruessen?-bel-ete
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
     mark: true
    });
console.log(slug); // Output: schoener-titel-laesst-gruessen!-bel-ete-!
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
     truncate: 20
    });
console.log(slug); // Output: schoener-titel
 
slug = getSlug("Schöner Titel läßt grüßen!? Bel été !", {
        maintainCase: true
    });
console.log(slug); // Output: Schoener-Titel-laesst-gruessen-Bel-ete
 
slug = getSlug("Äpfel & Birnen!", {
        lang: 'de'
    });
console.log(slug); // Output: aepfel-und-birnen
 
slug = getSlug("မြန်မာ သာဓက", {
        lang: 'my'
    });
console.log(slug); // Output: myanma-thadak
 
slug = getSlug("Apple & Pear!", {
        lang: 'en' // lang: "en" is default, just to clarify
    });
console.log(slug); // Output: apple-and-pear
 
slug = getSlug('Foo & Bar * Baz', {
        custom: {
            '&': ' doo '
        },
        uric:true
    });
console.log(slug); // Output: foo-doo-bar-baz
 
slug = getSlug('Foo ♥ Bar');
console.log(slug); // Output: foo-love-bar
 
slug = getSlug('Foo & Bar | (Baz) * Doo', {
        custom: {
            '*': 'Boo'
        },
        mark:true
    });
console.log(slug); // Output: foo-and-bar-or-(baz)-boo-doo
 
slug = getSlug('Foo and Bar or Baz', {
        custom: {
            'and': 'und',
            'or': ''
        }
    });
console.log(slug); // Output: foo-und-bar-baz
 
slug = getSlug('[Knöpfe]', {
        custom: [
            '[',
            ']'
        ]
    });
console.log(slug); // Output: [knoepfe]
 
slug = getSlug('NEXUS4 only $299');
console.log(slug); // Output: nexus-4-only-usd299
 
slug = getSlug('NEXUS4 only €299', {
        maintainCase: true
    });
console.log(slug); // Output: NEXUS-4-only-EUR299
 
slug = getSlug('Don\'t drink and drive', {
        titleCase: true
    });
console.log(slug); // Output: Don-t-Drink-And-Drive
 
slug = getSlug('Don\'t drink and drive', {
        titleCase: ['and']
    });
console.log(slug); // Output: Don-t-Drink-and-Drive
 
slug = getSlug('Foo & Bar ♥ Foo < Bar', {
        lang: false
    });
console.log(slug); // Output: foo-bar-foo-bar

createSlug([options])

options: {object|string} config object or separator string (see above)

Create your own specially configured function.

var options = {
        maintainCase: true,
        separator: '_'
    };
 
var mySlug = require('speakingurl').createSlug(options);
// in browser:
// var mySlug = createSlug(options);
 
var slug = mySlug("Schöner Titel läßt grüßen!? Bel été !");
console.log(slug); // Output: Schoener_Titel_laesst_gruessen_Bel_ete

Create your own specially configured function with title-case feature.

var options = {
        titleCase: [
            "a","an","and","as","at","but",
            "by","en","for","if","in","nor",
            "of","on","or","per","the","to","vs"
        ]
    };
 
var mySlug = require('speakingurl').createSlug(options);
// in browser:
// var mySlug = createSlug(options);
 
var slug = mySlug('welcome to the jungle');
console.log(slug); // Output: Welcome-to-the-Jungle

Changelog

see CHANGELOG.md

Tests

Build Status

npm test

Contribution

 
# fork pid/speakingurl on Github 
$ git clone git@github.com:<YOUR_USER>/speakingurl.git
cd speakingurl
$ npm install
# add your stuff 
# add tests 
# add example for new feature 
# add release info to CHANGELOG.md 
# add description/example to README.md 
$ gulp
$ commit files (speakingurl.min.js,...)
# if everything works fine, commit, push to your repository 
# create pull request 
 
# release new version / only for maintainer 
$ gulp bumpup --minor
$ gulp release
 
 
$

Release

$ gulp bumpup --patch
$ gulp
$ gulp release

Flattr

References

Use in other environments

Ports

Credits

License

The BSD 3-Clause License (BSD3)

Copyright (c) 2013-2015 Sascha Droste pid@posteo.net All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package Sidebar

Install

npm i speakingurl-add-korean

Weekly Downloads

29

Version

1.1.0

License

none

Last publish

Collaborators

  • rubydoc