From e82442c74b74f06901146e1ea78eaecde886766b Mon Sep 17 00:00:00 2001 From: Scimonster Date: Thu, 14 Feb 2019 23:29:45 +0200 Subject: [PATCH] Add geresh option, use bidi Unicode by default Bump version -- breaking change --- README.md | 14 +++++++++----- gematriya.js | 24 ++++++++++++------------ package.json | 2 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e0efc21..cd1b8aa 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/gematriya.js b/gematriya.js index 0d1ed8b..1f0c2d9 100644 --- a/gematriya.js +++ b/gematriya.js @@ -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 @@ -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()'); } @@ -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) { @@ -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 ? '״' : '"'); } } diff --git a/package.json b/package.json index 40b54ae..7cc6f6e 100644 --- a/package.json +++ b/package.json @@ -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": [