File tree Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Expand file tree Collapse file tree 2 files changed +25
-21
lines changed Original file line number Diff line number Diff line change 1
1
# pensador-api
2
+
2
3
🤔 Pensador é um pacote Node que traz frases de pensadores
3
4
4
5
## Instalação
5
6
6
7
```
7
- yarn add pensador-api
8
+ yarn add pensador-api
8
9
// or
9
10
npm install --save pensador-api
10
11
```
@@ -13,9 +14,7 @@ npm install --save pensador-api
13
14
14
15
Primeiro, importe o pacote e depois chame a função passando as opções.
15
16
16
-
17
- * NOTE* : pensador-api é assíncrono, logo você deve usar Promises ou Async/Await.
18
-
17
+ _ NOTE_ : pensador-api é assíncrono, logo você deve usar Promises ou Async/Await.
19
18
20
19
```
21
20
const pensador = require('pensador-api')
@@ -55,13 +54,14 @@ const array = await pensador({ term: "Elon Musk", max: 5 })
55
54
*/
56
55
```
57
56
58
-
59
57
## Opções
60
58
61
- * term * (obrigatória ) (string)
59
+ _ term _ (opcional ) (string)
62
60
63
61
Um termo a ser pesquisado. O pacote irá adicionar automaticamente o prefixo "frases de", padrão do site Pensador.com
64
62
65
- * max* (opcional) (integer)
63
+ Caso nenhum seja utilizado, o term padrao será "frases_curtas"
64
+
65
+ _ max_ (opcional) (integer)
66
66
67
- Número máximo de registros que o pacote deve retornar. Deixe me branco para capturar todos os disponíveis no termo.
67
+ Número máximo de registros que o pacote deve retornar. Deixe me branco para capturar todos os disponíveis no termo.
Original file line number Diff line number Diff line change @@ -3,19 +3,23 @@ const fetch = require("node-fetch"),
3
3
cheerio = require ( "cheerio" ) ,
4
4
iconv = require ( "iconv-lite" ) ;
5
5
6
- const baseUrl = "https://www.pensador.com/" ;
7
-
8
- module . exports = async options => {
9
- if ( options === undefined || options . term === undefined ) {
10
- _throw ( "A search term must be defined" ) ;
11
- }
12
-
13
- const searchTerm = slugify ( `frases de ${ options . term } ` , {
14
- replacement : "_" ,
15
- remove : / [ * + ~ . ( ) ' " ! : @ ] / g,
16
- lower : true
17
- } ) ;
6
+ const baseUrl = 'https://www.pensador.com/' ;
18
7
8
+ module . exports = async ( options ) => {
9
+ if ( typeof options == 'undefined' ) {
10
+ var options = { max : 10 } ;
11
+ }
12
+ // Default value for search term, Term is not mandatory anymore
13
+ var searchTerm = 'frases_curtas' ;
14
+ // if term is set then is changed to a new value
15
+ if ( options . term != 'undefined' ) {
16
+ searchTerm = slugify ( `frases de ${ options . term } ` , {
17
+ replacement : '_' ,
18
+ remove : / [ * + ~ . ( ) ' " ! : @ ] / g,
19
+ lower : true ,
20
+ } ) ;
21
+ }
22
+
19
23
let keepGoing = true ;
20
24
let current = 1 ;
21
25
@@ -96,4 +100,4 @@ module.exports = async options => {
96
100
97
101
function _throw ( m ) {
98
102
throw m ;
99
- }
103
+ }
You can’t perform that action at this time.
0 commit comments