Skip to content

Commit

Permalink
Esm migration (#651)
Browse files Browse the repository at this point in the history
* Esm migration

* updated cheerio ES6 imports and removed unnecessary comments

* Added missing properties in IAppItemFullDetail interface

* Replaced require examples with es6 imports

* Update README.md

* Update README.md

---------

Co-authored-by: Facundo Olano <[email protected]>
  • Loading branch information
jbigman and facundoolano authored Aug 7, 2023
1 parent 86af2cd commit b0ffa3e
Show file tree
Hide file tree
Showing 33 changed files with 338 additions and 374 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Retrieves the full detail of an application. Options:
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.app({appId: 'com.google.android.apps.translate'})
.then(console.log, console.log);
Expand Down Expand Up @@ -131,7 +131,7 @@ Retrieve a list of applications from one of the collections at Google Play. Opti
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.list({
category: gplay.category.GAME_ACTION,
Expand Down Expand Up @@ -184,7 +184,7 @@ Retrieves a list of apps that results of searching by the given term. Options:
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.search({
term: "panda",
Expand Down Expand Up @@ -230,7 +230,7 @@ Returns the list of applications by the given developer name. Options:
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.developer({devId: "DxCo Games"}).then(console.log);
```
Expand Down Expand Up @@ -270,7 +270,7 @@ Given a string returns up to five suggestion to complete a search query term. Op

Example:
```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.suggest({term: 'panda'}).then(console.log);
```
Expand Down Expand Up @@ -307,7 +307,7 @@ Options:
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

// This example will return 3000 reviews
// on a single call
Expand Down Expand Up @@ -404,7 +404,7 @@ Returns a list of similar apps to the one specified. Options:
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.similar({appId: "com.dxco.pandavszombies"}).then(console.log);
```
Expand Down Expand Up @@ -434,7 +434,7 @@ permission/description objects.
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.permissions({appId: "com.dxco.pandavszombies"}).then(console.log);
```
Expand All @@ -461,7 +461,7 @@ Returns the data safety information of an application. The data safety is catego
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.datasafety({appId: "com.dxco.pandavszombies"}).then(console.log);
```
Expand Down Expand Up @@ -565,7 +565,7 @@ Retrieve a full list of categories present from dropdown menu on Google Play.
Example:

```javascript
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

gplay.categories().then(console.log);
```
Expand All @@ -589,9 +589,9 @@ to avoid requesting the same data twice. The `memoized` function returns a
store object that caches its results:

```js
var store = require('google-play-scraper'); // regular non caching version
var memoized = require('google-play-scraper').memoized(); // cache with default options
var memoizedCustom = require('google-play-scraper').memoized({ maxAge: 1000 * 60 }); // cache with customized options
import {memoized as m} from "google-play-scraper"; // cache with default options
const memoized = m();// cache with customized options
const memoizedCustom = m({ maxAge: 1000 * 60 });// cache with customized options

// first call will hit google play and cache the results
memoized.developer({devId: "DxCo Games"}).then(console.log);
Expand All @@ -618,7 +618,7 @@ defines an upper bound to the amount of requests that will be attempted per seco
Once that limit is reached, further requests will be held until the second passes.

```js
var gplay = require('google-play-scraper');
import gplay from "google-play-scraper";

// the following method will perform batches of 10 requests per second
gplay.search({term: 'panda', throttle: 10}).then(console.log);
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export interface IAppItemFullDetail extends IAppItem {
reviews: number
histogram: { '1': number, '2': number, '3': number, '4': number, '5': number }
price: number
originalPrice?: number
discountEndDate?: string
free: boolean
currency: string
priceText: string
Expand Down Expand Up @@ -146,6 +148,9 @@ export interface IAppItemFullDetail extends IAppItem {
version: string
recentChanges: string
comments: string[]
hasEarlyAccess: boolean
preregister: boolean
isAvailableInPlayPass: boolean
}

export interface IReviewsItem {
Expand Down
59 changes: 33 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
'use strict';

const R = require('ramda');
const constants = require('./lib/constants');
const memoizee = require('memoizee');

const appMethod = require('./lib/app');
import R from 'ramda';
import { constants } from './lib/constants.js';
import memoizee from 'memoizee';
import appMethod from './lib/app.js';

import list from './lib/list.js';
import search from './lib/search.js';
import suggest from './lib/suggest.js';
import developer from './lib/developer.js';
import reviews from './lib/reviews.js';
import similar from './lib/similar.js';
import permissions from './lib/permissions.js';
import datasafety from './lib/datasafety.js';
import categories from './lib/categories.js';

const methods = {
app: appMethod,
list: require('./lib/list'),
search: R.partial(require('./lib/search'), [appMethod]),
suggest: require('./lib/suggest'),
developer: require('./lib/developer'),
reviews: require('./lib/reviews'),
similar: require('./lib/similar'),
permissions: require('./lib/permissions'),
datasafety: require('./lib/datasafety'),
categories: require('./lib/categories')
list,
search: R.partial(search, [appMethod]),
suggest,
developer,
reviews,
similar,
permissions,
datasafety,
categories
};

function memoized (opts) {
Expand All @@ -32,20 +39,20 @@ function memoized (opts) {
const mAppMethod = memoizee(appMethod, cacheOpts);

const otherMethods = {
list: require('./lib/list'),
search: R.partial(require('./lib/search'), [mAppMethod]),
suggest: require('./lib/suggest'),
developer: require('./lib/developer'),
reviews: require('./lib/reviews'),
similar: require('./lib/similar'),
permissions: require('./lib/permissions'),
datasafety: require('./lib/datasafety'),
categories: require('./lib/categories')
list,
search: R.partial(search, [mAppMethod]),
suggest,
developer,
reviews,
similar,
permissions,
datasafety,
categories
};

return Object.assign({ app: mAppMethod },
constants,
R.map(doMemoize, otherMethods));
}

module.exports = Object.assign({ memoized }, constants, methods);
export default Object.assign({ memoized }, constants, methods);
16 changes: 7 additions & 9 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
'use strict';

const R = require('ramda');
const queryString = require('querystring');
const request = require('./utils/request');
const scriptData = require('./utils/scriptData');
const { BASE_URL } = require('./constants');
const helper = require('./utils/mappingHelpers');
import R from 'ramda';
import queryString from 'querystring';
import request from './utils/request.js';
import scriptData from './utils/scriptData.js';
import { BASE_URL } from './constants.js';
import helper from './utils/mappingHelpers.js';

const PLAYSTORE_URL = `${BASE_URL}/store/apps/details`;

Expand Down Expand Up @@ -181,4 +179,4 @@ const MAPPINGS = {

};

module.exports = app;
export default app;
10 changes: 4 additions & 6 deletions lib/categories.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const request = require('./utils/request');
const cheerio = require('cheerio');
const { BASE_URL } = require('./constants');
import request from './utils/request.js';
import * as cheerio from 'cheerio';
import { BASE_URL } from './constants.js';

const PLAYSTORE_URL = `${BASE_URL}/store/apps`;
const CATEGORY_URL_PREFIX = '/store/apps/category/';
Expand Down Expand Up @@ -37,4 +35,4 @@ function extractCategories ($) {
return categoryIds;
}

module.exports = categories;
export default categories;
Loading

0 comments on commit b0ffa3e

Please sign in to comment.