Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Created November 3, 2011 01:42
Show Gist options
  • Save nijikokun/1335539 to your computer and use it in GitHub Desktop.
Save nijikokun/1335539 to your computer and use it in GitHub Desktop.
Less Than 140 Chars - JS

<= (chars 140)

A collection of js functions that are less than or equal to 140 characters.

  • t - Quick templating function with optional custom brackets (js | coffee)
/* t in coffeescript */
t = (s,o,p = '{',e = '}') ->
for own i of o
s = s.replace(new RegExp(p+i+e,'g'),o[i])
return s
// t
// Author: Nijikokun
// Description: Templating
// Usage:
//
// console.log(t('Hello {n} with {n} n', { n: '1'}))
//
function t (a,b,c,d){c=c||'{';d=d||'}';for(var e in b)e in b&&(a=a.replace(RegExp(c+e+d,'g'), b[e]));return a;}
@hakusaro
Copy link

hakusaro commented Nov 3, 2011

That's an interesting concept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment