Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urlFriendly.js #9

Open
jnbdz opened this issue Nov 9, 2015 · 0 comments
Open

urlFriendly.js #9

jnbdz opened this issue Nov 9, 2015 · 0 comments
Labels

Comments

@jnbdz
Copy link
Member

jnbdz commented Nov 9, 2015

/*

---
description: Clean a string to make it friendly for the URL.

license: MIT-style

authors:
- Jean-Nicolas Boulay Desjardins (http://jean-nicolas.name/)

requires:
 core/1.2.1:   '*'

provides:
- urlFriendly

...
*/

var urlFriendly = new Class({

    initialize: function(val){

        this.val = val;

    },

            escape: function(){

                    return escape(this.val);
            },

            humanReadable: function(){

                    return this.val
                    .toLowerCase()
                    .replace(/^\s+|\s+$/g, "") // trim leading and trailing spaces
                    .replace(/[_|\s]+/g, "-") // change all spaces and underscores to a hyphen
                    .replace(/[^a-z0-9-]+/g, "") // remove all non-alphanumeric characters except the hyphen
                    .replace(/[-]+/g, "-") // replace multiple instances of the hyphen with a single instance
                    .replace(/^-+|-+$/g, ""); // trim leading and trailing hyphens
            }

    });
@jnbdz jnbdz added the Proposal label Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant