Skip to content

Commit

Permalink
Add geresh option, use bidi Unicode by default
Browse files Browse the repository at this point in the history
Bump version -- breaking change
  • Loading branch information
Scimonster committed Feb 14, 2019
1 parent f9d5e9f commit e82442c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ A single function is available. Pass it a `Number` or `String`. Given a number,

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, 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 quoatation marks in the returned string. Like this:
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, {limit: 3}) // תשע"ד - cropped to 774
gematriya(5774, {limit: 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, {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
```
Expand Down
24 changes: 12 additions & 12 deletions gematriya.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* 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
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -62,9 +62,9 @@

function gematriya(num, options) {
if (options === undefined) {
var options = {limit: false, punctuate: true, order: false }
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()');
}
Expand All @@ -73,11 +73,11 @@
throw new TypeError('An object was not given as second argument')
}

var limit = options.limit
var punctuate = options.punctuate
var order = options.order
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) {
Expand Down Expand Up @@ -105,12 +105,12 @@
}, 0);
} else {
num = num.reverse().join('').replace(/יה/g,'טו').replace(/יו/g,'טז').split('');
if (punctuate) {

if (punctuate || geresh) {
if (num.length === 1) {
num.push("'");
num.push(geresh ? '׳' : "'");
} else if (num.length > 1) {
num.splice(-1, 0, '"');
num.splice(-1, 0, geresh ? '״' : '"');
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gematriya",
"version": "1.0.1",
"version": "2.0.0",
"author": "Eyal Schachter (https://github.com/Scimonster)",
"description": "Convert numbers to gematriya representation, and vice-versa.",
"keywords": [
Expand Down

0 comments on commit e82442c

Please sign in to comment.