the-amazing-quran-images
Version:
This repository contains images of the holly Quran in png format, and a small node module to handle them
44 lines (36 loc) • 1.18 kB
JavaScript
/**
* 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
*/
(() => { 'use strict';
let fs = require('fs');
module.exports = () => {
let model = {};
let _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) {
let surah = parseInt(surahNumber);
let 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) {
let path = getAyahPath(surahNumber, ayahNumber);
try { return fs.readFileSync(path, 'base64'); }
catch (e) { return false; }
}
return model;
};
})();