Comparing version 0.1.0 to 0.1.1
'use strict'; | ||
var toFastProperties = require('to-fast-properties'); | ||
var reduce = require('lodash.reduce'); | ||
function strord(a, b) { | ||
@@ -12,2 +15,7 @@ return a == b ? 0 : a < b ? -1 : 1; | ||
var charsLength = chars.length; | ||
var lookup = reduce(chars, function (accumulator, char, idx) { | ||
accumulator[char] = idx; | ||
return accumulator; | ||
}, {}); | ||
toFastProperties(lookup); | ||
@@ -27,7 +35,12 @@ var exports = between; | ||
function randstr(l) { | ||
// expect l >= 0 | ||
// expect l >= 0. if l | ||
var str = ''; | ||
while (l--) { | ||
str += chars[Math.floor(Math.random() * chars.length)]; | ||
while (l-- > 1) { | ||
str += chars[Math.floor(Math.random() * charsLength)]; | ||
} | ||
if (l == 0) { | ||
str += chars[Math.floor(Math.random() * (charsLength - 2)) + 1]; | ||
} | ||
return str; | ||
@@ -59,8 +72,6 @@ } | ||
while (i <= guard) { | ||
// TODO: build lookup table | ||
var _a = chars.indexOf(a[i]); | ||
var _b = chars.indexOf(b[i]); | ||
var _a = lookup[a[i]] || 0; | ||
var _b = lookup[b[i]]; | ||
if (_a == -1) _a = 0; | ||
if (_b == -1) _b = charsLength - 1; | ||
if (_b == void 0) _b = charsLength - 1; | ||
@@ -67,0 +78,0 @@ i++; |
{ | ||
"name": "between2", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "generate arbitary strings that sort between two strings. fork of between.", | ||
@@ -30,3 +30,7 @@ "main": "modules/index.js", | ||
"mocha": "^2.2.5" | ||
}, | ||
"dependencies": { | ||
"lodash.reduce": "^3.1.2", | ||
"to-fast-properties": "^1.0.1" | ||
} | ||
} |
@@ -43,10 +43,12 @@ # between2 [![Build Status](https://travis-ci.org/Dashed/between2.svg)](https://travis-ci.org/Dashed/between2) | ||
### `strord(a)` | ||
### `strord(a, b)` | ||
TBA | ||
Compares two strings, `a` and `b`, lexicographically. Returns `0` if `a == b`; `-1` if `a` is lexicographically less than `b`; `1` if `a` is lexicographically greater than `b`. | ||
### `randstr(len)` | ||
Generate random string with length `len`. | ||
Generate random string with length `len` using `chars`. Expects `len >= 0`. | ||
**NOTE:** The string's last character will never be either the `between.lo` character or the `between.hi` character for `chars` of size greater than two. This is intended so that this string, `a`, may be used as a reference point to generate strings that will be able to sort between `a` and any other string distinct from `a`. For `chars` of size 2, the `between.hi` character will be used. | ||
### `inject(chars)` | ||
@@ -56,2 +58,4 @@ | ||
**NOTE:** It's expected that `chars` is at least 2 distinct characters long. | ||
### `between.lo` and `between.hi` | ||
@@ -58,0 +62,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7743
74
70
2
+ Addedlodash.reduce@^3.1.2
+ Addedto-fast-properties@^1.0.1
+ Addedlodash._basecallback@3.3.1(transitive)
+ Addedlodash._baseeach@3.0.4(transitive)
+ Addedlodash._baseisequal@3.0.7(transitive)
+ Addedlodash._basereduce@3.0.2(transitive)
+ Addedlodash._bindcallback@3.0.1(transitive)
+ Addedlodash._getnative@3.9.1(transitive)
+ Addedlodash.isarguments@3.1.0(transitive)
+ Addedlodash.isarray@3.0.4(transitive)
+ Addedlodash.istypedarray@3.0.6(transitive)
+ Addedlodash.keys@3.1.2(transitive)
+ Addedlodash.pairs@3.0.1(transitive)
+ Addedlodash.reduce@3.1.2(transitive)
+ Addedto-fast-properties@1.0.3(transitive)