Skip to content

Commit

Permalink
Switch CJS requires to ESM imports
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwhitman committed Feb 1, 2022
1 parent 8b5eaef commit 0f18e80
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/internal/chats.js
@@ -1,4 +1,4 @@
var PushBullet = require('../pushbullet');
import PushBullet from '../pushbullet.js';

/**
* Get a list of current chats.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/devices.js
@@ -1,4 +1,4 @@
var PushBullet = require('../pushbullet');
import PushBullet from '../pushbullet.js';

/**
* Get a list of devices which can be pushed to.
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/encryption.js
@@ -1,4 +1,4 @@
var forge = require('node-forge');
import forge from 'node-forge';

/**
* Encryption module for the PushBullet API.
Expand All @@ -8,7 +8,7 @@ var forge = require('node-forge');
* @param {String} encryptionPassword End-to-End encryption password set by the user.
* @param {String} userIden The iden of the user (aquired e.g. by the /me request).
*/
function Encryption(encryptionPassword, userIden) {
export default function Encryption(encryptionPassword, userIden) {
var derivedKeyLength = 32;
var iterations = 30000;
var pseudorandomFunction = forge.md.sha256.create();
Expand All @@ -17,8 +17,6 @@ function Encryption(encryptionPassword, userIden) {
this.encryptionKey = encryptionKey;
}

module.exports = Encryption;

/**
* Decodes a base-64 encoded string.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/ephemerals.js
@@ -1,6 +1,6 @@
var clone = require('clone');
import clone from 'clone';

var PushBullet = require('../pushbullet');
import PushBullet from '../pushbullet.js';

/**
* Send an SMS.
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/pushes.js
@@ -1,9 +1,9 @@
var fs = require('fs');
var http = require('http');
var mime = require('mime');
var path = require('path');
var request = require('request-promise-native');
var PushBullet = require('../pushbullet');
import fs from 'fs';
import http from 'http';
import mime from 'mime';
import path from 'path';
import request from 'request-promise-native';
import PushBullet from '../pushbullet.js';

/**
* Push a note to a device.
Expand Down
10 changes: 4 additions & 6 deletions lib/internal/stream.js
@@ -1,8 +1,8 @@
/*global module,require*/

var util = require('util');
var events = require('events');
var WebSocket = require('ws');
import util from 'util';
import events from 'events';
import WebSocket from 'ws';

var STREAM_BASE = 'wss://stream.pushbullet.com/websocket';

Expand All @@ -12,7 +12,7 @@ var STREAM_BASE = 'wss://stream.pushbullet.com/websocket';
* @param {String} apiKey PushBullet API key.
* @param {Encryption} encryption Encryption instance.
*/
function Stream(apiKey, encryption) {
export default function Stream(apiKey, encryption) {
this.apiKey = apiKey;
this.encryption = encryption;

Expand All @@ -21,8 +21,6 @@ function Stream(apiKey, encryption) {

util.inherits(Stream, events.EventEmitter);

module.exports = Stream;

/**
* Connect to the stream.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/subscriptions.js
@@ -1,4 +1,4 @@
var PushBullet = require('../pushbullet');
import PushBullet from '../pushbullet.js';

/**
* Get a list of current subscriptions.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/users.js
@@ -1,4 +1,4 @@
var PushBullet = require('../pushbullet');
import PushBullet from '../pushbullet.js';

/**
* Get information for the current user.
Expand Down
24 changes: 11 additions & 13 deletions lib/pushbullet.js
@@ -1,18 +1,18 @@
/*global module,require*/

var http = require('http');
var request = require('request-promise-native');
import http from 'http';
import request from 'request-promise-native';

var Encryption = require('./internal/encryption');
var Stream = require('./internal/stream');
import Encryption from './internal/encryption.js';
import Stream from './internal/stream.js';

/**
* PushBullet API abstraction module.
*
* @param {String} apiKey PushBullet API key.
* @param {Object} options Options object.
*/
function PushBullet(apiKey, options) {
export default function PushBullet(apiKey, options) {
if ( ! apiKey) {
throw new Error('API Key is required');
}
Expand Down Expand Up @@ -44,8 +44,6 @@ PushBullet.CHANNELS_END_POINT = PushBullet.API_BASE + '/channel-info';
PushBullet.CHATS_END_POINT = PushBullet.API_BASE + '/chats';
PushBullet.EPHEMERALS_END_POINT = PushBullet.API_BASE + '/ephemerals';

module.exports = PushBullet;

/**
* Enables End-to-End encryption.
*
Expand Down Expand Up @@ -183,9 +181,9 @@ PushBullet.prototype.handleError = function handleError(error, response, callbac
});
};

require('./internal/chats');
require('./internal/devices');
require('./internal/ephemerals');
require('./internal/pushes');
require('./internal/subscriptions');
require('./internal/users');
import './internal/chats.js';
import './internal/devices.js';
import './internal/ephemerals.js';
import './internal/pushes.js';
import './internal/subscriptions.js';
import './internal/users.js';
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "2.4.0",
"description": "Use PushBullets REST API",
"main": "index.js",
"type": "module",
"scripts": {
"test": "./node_modules/.bin/mocha",
"lint": "./node_modules/.bin/eslint ."
Expand Down

0 comments on commit 0f18e80

Please sign in to comment.