Comparing version 1.0.1 to 2.0.0
@@ -14,6 +14,6 @@ /* | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
@@ -64,7 +64,22 @@ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
function gematriya(num, limit) { | ||
function gematriya(num, options) { | ||
if (options === undefined) { | ||
var options = {limit: false, punctuate: true, order: false, geresh: true}; | ||
} | ||
if (typeof num !== 'number' && typeof num !== 'string') { | ||
throw new TypeError('non-number or string given to gematriya()'); | ||
} | ||
if (typeof options !== 'object' || options === null){ | ||
throw new TypeError('An object was not given as second argument') | ||
} | ||
var limit = options.limit; | ||
var order = options.order; | ||
var punctuate = typeof options.punctuate === 'undefined' ? true : options.punctuate; | ||
var geresh = typeof options.geresh === 'undefined' && punctuate ? true : options.geresh; | ||
var str = typeof num === 'string'; | ||
if (str) { | ||
@@ -80,3 +95,3 @@ num = num.replace(/('|")/g,''); | ||
if (str) { | ||
return limit && numbers[n] < numbers[num[i - 1]] && numbers[n] < 100 ? numbers[n] * 1000 : numbers[n]; | ||
return order && numbers[n] < numbers[num[i - 1]] && numbers[n] < 100 ? numbers[n] * 1000 : numbers[n]; | ||
} else { | ||
@@ -97,6 +112,8 @@ if (parseInt(n, 10) * Math.pow(10, i) > 1000) { | ||
if (num.length === 1) { | ||
num.push("'"); | ||
} else if (num.length > 1) { | ||
num.splice(-1, 0, '"'); | ||
if (punctuate || geresh) { | ||
if (num.length === 1) { | ||
num.push(geresh ? '׳' : "'"); | ||
} else if (num.length > 1) { | ||
num.splice(-1, 0, geresh ? '״' : '"'); | ||
} | ||
} | ||
@@ -103,0 +120,0 @@ |
{ | ||
"name": "gematriya", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"author": "Eyal Schachter (https://github.com/Scimonster)", | ||
@@ -5,0 +5,0 @@ "description": "Convert numbers to gematriya representation, and vice-versa.", |
@@ -11,3 +11,3 @@ # Gematriya | ||
``` | ||
```bash | ||
npm install gematriya | ||
@@ -23,10 +23,18 @@ bower install gematriya | ||
When passing a string, by default, it just adds up the numbers, regardless of place. By passing `true` as a second parameter, it will treat it as being ordered, as per the output (see below). | ||
When passing a string, by default, it just adds up the numbers, regardless of place. By passing `{order: true}` as a second parameter, it will treat it as being ordered, as per the output (see below). | ||
When passing a number, a second parameter is available, `limit`. This will limit the length of the returned string to a number of digits. For example: | ||
When passing a number, an optional options object is available as a second parameter. Setting a number as a value for the `limit` key will limit the length of the returned string to a number of digits. Setting false as the value for the `punctuate` key will remove double and single quotation marks in the returned string. Setting `geresh` to false will use ASCII single/double quotes instead of Hebrew geresh/gershayim Unicode characters. Like this: | ||
```js | ||
gematriya(5774) // התשע"ד - ordinary | ||
gematriya(5774, 3) // תשע"ד - cropped to 774 | ||
gematriya(5774, 7) // התשע"ד - kept at 5774 | ||
gematriya(5774) // התשע״ד - ordinary | ||
gematriya(5774, {limit: 3}) // תשע״ד - cropped to 774 | ||
gematriya(5774, {limit: 7}) // התשע״ד - kept at 5774 | ||
gematriya(5774, {punctuate: false}) // 'התשעד' - removed quotation marks | ||
gematriya(5774, {punctuate: true}) // 'התשע״ד' - with quotation marks | ||
gematriya(5774, {geresh: false}) // 'התשע"ד' - with quotation marks | ||
gematriya(5774, {punctuate: false, limit: 3}) // 'תשעד' - options can be combined | ||
gematriya(3) // 'ג׳' - note the geresh is RTL | ||
gematriya(3, {geresh: false}) // - "ג'" - the apostrophe is not | ||
gematriya('התשעד', {order: true}) // 5774 - treats the characters as an ordered number | ||
gematriya('התשעד', {order: false}) // 779 - Adds up all the characters | ||
``` | ||
@@ -33,0 +41,0 @@ |
7591
133
43