Adaptation of Prototype\'s Truncate function


/ Published in: JavaScript
Save to your folder(s)

I just ripped it from Prototype for use in my jQuery based code.


Copy this code and paste it in your HTML
  1. function truncate(text, length, truncation) {
  2. length = length || 30;
  3. truncation = (typeof(truncation) == 'undefined') ? '...' : truncation;
  4. return text.length > length ?
  5. text.slice(0, length - truncation.length) + truncation : String(text);
  6. }
  7.  
  8. truncate("Hello World",10,'...');

URL: https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.