]> gerrit.simantics Code Review - simantics/district.git/blob - shim.js
26cbdb1366be10eb4c665e3beab7559ca681d8f4
[simantics/district.git] / shim.js
1 'use strict';
2
3 var toInteger = require('../../../number/to-integer')
4   , value     = require('../../../object/valid-value')
5
6   , min = Math.min, max = Math.max;
7
8 module.exports = function (searchString/*, endPosition*/) {
9         var self, start, endPos;
10         self = String(value(this));
11         searchString = String(searchString);
12         endPos = arguments[1];
13         start = ((endPos == null) ? self.length :
14                         min(max(toInteger(endPos), 0), self.length)) - searchString.length;
15         return (start < 0) ? false : (self.indexOf(searchString, start) === start);
16 };