UNPKG

the-amazing-quran-images

Version:

This repository contains images of the holly Quran in png format, and a small node module to handle them

51 lines (41 loc) 1.23 kB
'use strict'; /** * This module is a simple handler to retreive a png of an ayah of the Quran. * You can either get it in base64 or retreive the path to png */ (function () { 'use strict'; var fs = require('fs'); module.exports = function () { var model = {}; var _dirPath = '/images/'; model.getAyahPath = getAyahPath; model.getAyahBase64 = getAyahBase64; /** * Return the path to the ayah png file * @param {Int} surahNumber * @param {Int} ayahNumber * @return {String} Path to the png file */ function getAyahPath(surahNumber, ayahNumber) { var surah = parseInt(surahNumber); var ayah = parseInt(ayahNumber); return __dirname + _dirPath + surah + '/' + surah + '_' + ayah + '.png'; } /** * Return the ayah png file converted in base64 * @param {Int} surahNumber * @param {Int} ayahNumber * @return {String} The ayah in base64 */ function getAyahBase64(surahNumber, ayahNumber) { var path = getAyahPath(surahNumber, ayahNumber); try { return fs.readFileSync(path, 'base64'); } catch (e) { return false; } } return model; }; })();