-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91329ad
Showing
5 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2014 Eyal Schachter | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
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 | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Gematriya | ||
|
||
[Gematriya/Gematria](https://en.wikipedia.org/wiki/Gematria), or perhaps more accurately, [Hebrew numerals](https://en.wikipedia.org/wiki/Hebrew_numerals), is a system of writing numbers as Hebrew letters. This JavaScript module allows for easy conversion between gematriya and JavaScript `Number` types. | ||
|
||
This code was originally written for [hebcal/hebcal-js](https://github.com/hebcal/hebcal-js). | ||
|
||
## Install | ||
|
||
Install gematriya from NPM, bower, or just take the `gematriya.js` script from this repo. | ||
|
||
``` | ||
npm install gematriya | ||
bower install gematriya | ||
``` | ||
|
||
## API | ||
|
||
On the client side, the API is available through the global function `gematriya`. In Node, `require('gematriya')`. | ||
|
||
A single function is available. Pass it a `Number` or `String`. Given a number, it will return the string representation. Given a gematriya string, it will return the number it represents. | ||
|
||
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: | ||
|
||
```js | ||
gematriya(5774) // התשע"ד - ordinary | ||
gematriya(5774, 3) // תשע"ד - cropped to 774 | ||
gematriya(5774, 7) // התשע"ד - kept at 5774 | ||
``` | ||
|
||
## License | ||
|
||
Licensed MIT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "gematriya", | ||
"main": "index.js", | ||
"version": "1.0.0", | ||
"authors": [ | ||
"Scimonster <[email protected]>" | ||
], | ||
"description": "Convert numbers to gematriya representation, and vice-versa.", | ||
"main": "gematriya.js", | ||
"moduleType": [ | ||
"node" | ||
], | ||
"keywords": [ | ||
"hebrew", | ||
"gematriya", | ||
"numbers" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://github.com/Scimonster/js-gematriya" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Convert numbers to gematriya representation, and vice-versa. | ||
* | ||
* Licensed MIT. | ||
* | ||
* Copyright (c) 2014 Eyal Schachter | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* 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 | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
(function(){ | ||
var letters = {}, numbers = { | ||
'': 0, | ||
א: 1, | ||
ב: 2, | ||
ג: 3, | ||
ד: 4, | ||
ה: 5, | ||
ו: 6, | ||
ז: 7, | ||
ח: 8, | ||
ט: 9, | ||
י: 10, | ||
כ: 20, | ||
ל: 30, | ||
מ: 40, | ||
נ: 50, | ||
ס: 60, | ||
ע: 70, | ||
פ: 80, | ||
צ: 90, | ||
ק: 100, | ||
ר: 200, | ||
ש: 300, | ||
ת: 400, | ||
תק: 500, | ||
תר: 600, | ||
תש: 700, | ||
תת: 800, | ||
תתק: 900, | ||
תתר: 1000 | ||
}, i; | ||
for (i in numbers) { | ||
letters[numbers[i]] = i; | ||
} | ||
|
||
function gematriya(num, limit) { | ||
if (typeof num !== 'number' && typeof num !== 'string') { | ||
throw new TypeError('non-number or string given to gematriya()'); | ||
} | ||
var str = typeof num === 'string'; | ||
if (str) { | ||
num = num.replace(/('|")/g,''); | ||
} | ||
num = num.toString().split('').reverse(); | ||
if (!str && limit) { | ||
num = num.slice(0, limit); | ||
} | ||
|
||
num = num.map(function g(n,i){ | ||
if (str) { | ||
return numbers[n] < numbers[num[i - 1]] && numbers[n] < 100 ? numbers[n] * 1000 : numbers[n]; | ||
} else { | ||
if (parseInt(n, 10) * Math.pow(10, i) > 1000) { | ||
return g(n, i-3); | ||
} | ||
return letters[parseInt(n, 10) * Math.pow(10, i)]; | ||
} | ||
}); | ||
|
||
if (str) { | ||
return num.reduce(function(o,t){ | ||
return o + t; | ||
}, 0); | ||
} else { | ||
num = num.reverse().join('').replace(/יה/g,'טו').replace(/יו/g,'טז').split(''); | ||
|
||
if (num.length === 1) { | ||
num.push("'"); | ||
} else if (num.length > 1) { | ||
num.splice(-1, 0, '"'); | ||
} | ||
|
||
return num.join(''); | ||
} | ||
} | ||
|
||
if (typeof module !== 'undefined') { | ||
module.exports = gematriya; | ||
} else { | ||
window.gematriya = gematriya; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "gematriya", | ||
"version": "1.0.0", | ||
"author": "Eyal Schachter (https://github.com/Scimonster)", | ||
"description": "Convert numbers to gematriya representation, and vice-versa.", | ||
"keywords": [ | ||
"hebrew", | ||
"gematriya", | ||
"numbers" | ||
], | ||
"main": "gematriya.js", | ||
"homepage": "https://github.com/Scimonster/js-gematriya", | ||
"bugs": "https://github.com/Scimonster/js-gematriya/issues", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Scimonster/js-gematriya.git" | ||
} | ||
} |