Giter Club home page Giter Club logo

quran's Introduction

quran

node.js interface to Holy Quran. See the javascript and websql versions at http://qzaidi.github.io/quran.

Installation

npm install quran

Usage

var quran = require('quran');

Fetch the first verse of second chapter

quran.get(2,1,function(err,verse) {
  if (!err) {
    console.log('Verse 1: Chapter 1: ' + verse.arabic);
  }
});

Fetch the first chapter

quran.get(1,function(err,verses) {
  if (!err) {
    console.log('Chapter 1: ' + verses.join(','));
  }
});

verses is an array, so you can join them in the above.

.get is simply a wrapper on select, so you can directly invoke it and do advanced filtering, like getting verse 2-4 of first chapter.

quran.select({ chapter: 1}, { offset: 1, limit: 3}, function(err,verses) {
  if (!err) {
    console.log(verses);
  }
});

[
  { chapter: 1,
    verse: 1,
    ar: 'بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ' },
  { chapter: 1,
    verse: 2,
    ar: 'ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ' },
  { chapter: 1, verse: 3, ar: 'ٱلرَّحْمَٰنِ ٱلرَّحِيمِ' } 
]

verses is an array of objects, and has additional info (chapter number, verse number).

The second argument to select is optional.

If you want to fetch multiple verses, not necessarily in sequence, use an array to specify this.

quran.select({ chapter: 1, verse: [ 2, 4, 6 ]}, function(err,verses) {
  if (!err) {
    console.log(verses);
  }
});

[ { chapter: 1,
    verse: 2,
    ar: 'ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ'
  },
  { 
    chapter: 1, 
    verse: 4, 
    ar: 'مَٰلِكِ يَوْمِ ٱلدِّينِ' 
  },
  { chapter: 1,
    verse: 6,
    ar: 'ٱهْدِنَا ٱلصِّرَٰطَ ٱلْمُسْتَقِيمَ'
  } 
]

Currently, only arabic text and english, hindi and urdu translations are supported, to limit package size. You can however, easily add translations to this package. Open an issue if you want to.

To fetch both the arabic text and translation, set the language option to en.

quran.select({ chapter: 1}, { offset: 1, limit: 3, language: 'en'}, function(err,verses) {
  if (!err) {
    console.log(verses);
  }
});

Similarly for hindi

Code:
quran.select({ chapter: 1}, { offset: 1, limit: 3, language: 'hi'}, function(err,verses) {
  if (!err) {
    console.log(verses);
  }
});
Output
[ 
  { chapter: 1,
    verse: 1,
    ar: 'بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ',
    hi: 'अल्लाह के नाम से जो रहमान व रहीम है।',
    translator: 'hindi' },
  { chapter: 1,
    verse: 2,
    ar: 'ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ',
    hi: 'तारीफ़ अल्लाह ही के लिये है जो तमाम क़ायनात का रब है।',
    translator: 'hindi' },
  { chapter: 1,
    verse: 3,
    ar: 'ٱلرَّحْمَٰنِ ٱلرَّحِيمِ',
    hi: 'रहमान और रहीम है।',
    translator: 'hindi' } 
]

Want multiple translations at once? Use an array when specifying language

quran.select({ chapter: 1, verse: [ 2, 4, 6 ]}, 
             { language: ['ur', 'en ] }, function(err,verses) {
  if (!err) {
    console.log(verses);
  }
});

[ { chapter: 1,
    verse: 2,
    ar: 'ٱلْحَمْدُ لِلَّهِ رَبِّ ٱلْعَٰلَمِينَ',
    en: 'All praise is due to Allah, the Lord of the Worlds.',
    ur: 'ساری تعریف اللہ کے لئے ہے جو عالمین کا پالنے والا ہے'
  },
  { chapter: 1,
    verse: 4,
    ar: 'مَٰلِكِ يَوْمِ ٱلدِّينِ',
    en: 'Master of the Day of Judgment.',
    ur: 'روزِقیامت کا مالک و مختار ہے' 
  },
  { chapter: 1,
    verse: 6,
    ar: 'ٱهْدِنَا ٱلصِّرَٰطَ ٱلْمُسْتَقِيمَ',
    en: 'Keep us on the right path.',
    ur: 'ہمیں سیدھے راستہ کی ہدایت فرماتا رہ' 
  } 
] 

You can also fetch meta data about a chapter

quran.chapter(1,function(err,info) {
  if (!err) {
    console.log(info);
  }
});

Or all the chapters, by omitting the optional argument

quran.chapter(function(err,info) {
  if (!err) {
    console.log(info);
  }
});

To access by juz, for example, first 10 verses of juz 28, use this pattern

quran.juz(28,function(err,j) {
  console.log(err || j[0]);
  if (!err) {
    quran.select({ chapter: j[0].surah }, { offset: j[0].ayah-1, limit: 10 }, function(err,verses) {
      console.log(err || verses);
    });
  }
});

To search in a translation, use the search API

quran.search('en','islam',function(err,verses) {
  // verses is an array of verses matching 'islam'
});

See Also

The npm module stores quran db as a sqlite database and exposes it via an API. With webSQL, it is possible to do the same for a pure javascript application, without requiring a server side component. That's the idea behind Quran browser. There is also a javascript version which pulls data from a [google spreadsheet] (http://qzaidi.github.io/quran/javascript), and another one using firebase, which can be easily embedded on a website.

Linting

You can run eslint to check your code for best practices: http://eslint.org/. A local install of eslint as well as the the standard linting rule set is included as part of dev dependencies for this package and you can use the following convenient command to run the linter on all JavaScript files in this package:

npm run lint

Run Unit Tests

Some basic tests are included, which are written using ava: https://github.com/avajs. Here's how you install ava:

npm install -g ava

Once you have ava, you can run the tests:

npm test

Credits

This work is based on Quran Text and Translations made available by http://tanzil.net.

Sites using this package

http://duas.mobi/quran.

To add yours, submit a pull request.

Known Issues

quran.select has some unsafe joins to fetch translations and can be abused. User should sanitise what is passed in as language options, or they could use quran.safe to wrap the calls (see test/select.js#FetchUnsupportedLanguage)

quran's People

Contributors

infacq avatar qzaidi avatar tjaffri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quran's Issues

Add firebase

Firebase based API can be another alternative to google spreadsheets

Thank you for this effort

Asalamu Alaykum

I am building an application that may utilize this npm module, are you planning on adding any direct meta data methods. Things like getJuzBySurah(), getJuzByVerse(). If you want to connect or need help building it please let me know

Please download a snapshot of the Qur'an data

I don't think tanzil.net updates their data often. But your download link currently looks broken (they respond to download.html, not download.php). I think it's worth downloading a static copy of the data, and either deferring to the API if it doesn't exist, or trying to update it on the first run of the app or something.

Clarify License

Please clarify the license you are publishing this code under. This will help adoption of this library.

Since you are using tanzil.net, I assume you intended to use CC-BY-3.0 (same as them)? Reference: http://tanzil.net/download/

Arabic Text Issue

The arabic text is not rendering correctly in windows cmd/terminal also not in vscode as well.
image

sqlite injection attack

The way multiple languages are supported currently lead to possible sql injection. In building the query string with join, this needs to be fixed.

Can't install on Windows

Assalamu'alaikum wr wb

I try to install this package on Windows 7 environment with Node installed. When I run command line "npm install quran, it stopped after moment. I include file log.

npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'quran' ]
2 info using [email protected]
3 info using [email protected]
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData quran
8 silly fetchNamedPackageData quran
9 silly mapToRegistry name quran
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry https://registry.npmjs.org/
12 silly mapToRegistry data Result {
12 silly mapToRegistry raw: 'quran',
12 silly mapToRegistry scope: null,
12 silly mapToRegistry escapedName: 'quran',
12 silly mapToRegistry name: 'quran',
12 silly mapToRegistry rawSpec: '',
12 silly mapToRegistry spec: 'latest',
12 silly mapToRegistry type: 'tag' }
13 silly mapToRegistry uri https://registry.npmjs.org/quran
14 verbose request uri https://registry.npmjs.org/quran
15 verbose request no auth needed
16 info attempt registry request try #1 at 7:44:27 PM
17 verbose request id 9af97d561f140d68
18 http request GET https://registry.npmjs.org/quran
19 http 200 https://registry.npmjs.org/quran
20 verbose headers { server: 'nginx/1.4.6 (Ubuntu)',
20 verbose headers 'content-type': 'application/json',
20 verbose headers 'last-modified': 'Sat, 26 Sep 2015 04:02:21 GMT',
20 verbose headers 'content-encoding': 'gzip',
20 verbose headers 'cache-control': 'max-age=300',
20 verbose headers 'content-length': '3206',
20 verbose headers 'accept-ranges': 'bytes',
20 verbose headers date: 'Thu, 13 Apr 2017 12:44:31 GMT',
20 verbose headers via: '1.1 varnish',
20 verbose headers age: '0',
20 verbose headers connection: 'keep-alive',
20 verbose headers 'x-served-by': 'cache-sin18027-SIN',
20 verbose headers 'x-cache': 'MISS',
20 verbose headers 'x-cache-hits': '0',
20 verbose headers 'x-timer': 'S1492087471.810195,VS0,VE541',
20 verbose headers vary: 'Accept-Encoding' }
21 silly get cb [ 200,
21 silly get { server: 'nginx/1.4.6 (Ubuntu)',
21 silly get 'content-type': 'application/json',
21 silly get 'last-modified': 'Sat, 26 Sep 2015 04:02:21 GMT',
21 silly get 'content-encoding': 'gzip',
21 silly get 'cache-control': 'max-age=300',
21 silly get 'content-length': '3206',
21 silly get 'accept-ranges': 'bytes',
21 silly get date: 'Thu, 13 Apr 2017 12:44:31 GMT',
21 silly get via: '1.1 varnish',
21 silly get age: '0',
21 silly get connection: 'keep-alive',
21 silly get 'x-served-by': 'cache-sin18027-SIN',
21 silly get 'x-cache': 'MISS',
21 silly get 'x-cache-hits': '0',
21 silly get 'x-timer': 'S1492087471.810195,VS0,VE541',
21 silly get vary: 'Accept-Encoding' } ]
22 verbose get saving quran to C:\Users\Ahmadie Thaha\AppData\Roaming\npm-cache\registry.npmjs.org\quran.cache.json
23 verbose correctMkdir C:\Users\Ahmadie Thaha\AppData\Roaming\npm-cache correctMkdir not in flight; initializing
24 silly install normalizeTree
25 silly loadCurrentTree Finishing
26 silly loadIdealTree Starting
27 silly install loadIdealTree
28 silly cloneCurrentTree Starting
29 silly install cloneCurrentTreeToIdealTree
30 silly cloneCurrentTree Finishing
31 silly loadShrinkwrap Starting
32 silly install loadShrinkwrap
33 silly loadShrinkwrap Finishing
34 silly loadAllDepsIntoIdealTree Starting
35 silly install loadAllDepsIntoIdealTree
36 silly rollbackFailedOptional Starting
37 silly rollbackFailedOptional Finishing
38 silly runTopLevelLifecycles Finishing
39 silly install printInstalled
40 verbose stack Error: Refusing to install quran as a dependency of itself
40 verbose stack at checkSelf (C:\Program Files\nodejs\node_modules\npm\lib\install\validate-args.js:53:14)
40 verbose stack at Array. (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\bind-actor.js:15:8)
40 verbose stack at LOOP (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:15:14)
40 verbose stack at chain (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:20:5)
40 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\install\validate-args.js:16:5
40 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:52:35
40 verbose stack at Array.forEach (native)
40 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:52:11
40 verbose stack at Array.forEach (native)
40 verbose stack at asyncMap (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:51:8)
41 verbose cwd d:\My Download\qzaidi.github.io\quran-master
42 error Windows_NT 6.1.7601
43 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "quran"
44 error node v6.10.0
45 error npm v3.10.10
46 error code ENOSELF
47 error Refusing to install quran as a dependency of itself
48 error If you need help, you may report this error at:
48 error https://github.com/npm/npm/issues
49 verbose exit [ 1, true ]

is it possible to pass multiple references at once?

Selams

To paint an arbitrary sequence of verses, say the search results of a word search, what do we need to do? Following shows 5 verses with one script call:

<div id='verses2'></div>
    <div id='translation'></div>
    <script 
      chapter=93 verse=6 count=5 selector='#verses2' trans='#translation'
      src="http://qzaidi.github.io/quran/js/quran.js">
    </script>

however, what if you want to display, say 36:1 55:3 45:3? Do I need 3 similar snippets? If I need to

SRC'ing the "http://qzaidi.github.io/quran/js/quran.js" more than 1 time does not make sense to me. Could you tell me it is totally OK to do so?

Or, Is there a way to pass something like this ( ids="36:1,55:3,45:3" ) as demonstrated below?

<div id='verses2'></div>
    <div id='translation'></div>
    <script 
      **ids="36:1,55:3,45:3"** selector='#verses2' trans='#translation'
      src="http://qzaidi.github.io/quran/js/quran.js">
    </script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.