Created
          March 28, 2010 22:31 
        
      - 
      
- 
        Save alandipert/347085 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Imap.prototype.next: ((id, fmt) -> | |
| prefix: (for i in [0...fmt.replace(/0/g, "").length] | |
| (-> this.charAt(Math.random()*this.length)) | |
| .call("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") | |
| ).join("") | |
| fmt: fmt.replace(/X/g, "") | |
| return ( -> | |
| id: ++id % (parseInt(fmt.replace(/0/g, "9")) + 1) | |
| ret: fmt + id | |
| prefix + ret.substring(ret.length - fmt.length) | |
| ) | |
| )(0, "XXXX0000") | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment