Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 1
/*
2
 * typeahead.js
3
 * https://github.com/twitter/typeahead.js
4
 * Copyright 2013-2014 Twitter, Inc. and other contributors; Licensed MIT
5
 */
6
 
7
var tokenizers = (function() {
8
  'use strict';
9
 
10
  return {
11
    nonword: nonword,
12
    whitespace: whitespace,
13
    obj: {
14
      nonword: getObjTokenizer(nonword),
15
      whitespace: getObjTokenizer(whitespace)
16
    }
17
  };
18
 
19
  function whitespace(str) {
20
    str = _.toStr(str);
21
    return str ? str.split(/\s+/) : [];
22
  }
23
 
24
  function nonword(str) {
25
    str = _.toStr(str);
26
    return str ? str.split(/\W+/) : [];
27
  }
28
 
29
  function getObjTokenizer(tokenizer) {
30
    return function setKey(/* key, ... */) {
31
      var args = [].slice.call(arguments, 0);
32
 
33
      return function tokenize(o) {
34
        var tokens = [];
35
 
36
        _.each(args, function(k) {
37
          tokens = tokens.concat(tokenizer(_.toStr(o[k])));
38
        });
39
 
40
        return tokens;
41
      };
42
    };
43
  }
44
})();