Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate code from commonJS to EMS #99

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require: '@babel/register'
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Javascript library to access the Zulip API
### With API Key

```js
const zulipInit = require('zulip-js');
import zulipInit from 'zulip-js';

const config = {
username: process.env.ZULIP_USERNAME,
apiKey: process.env.ZULIP_API_KEY,
Expand All @@ -28,7 +29,8 @@ const config = {
You will need to first retrieve the API key by calling `await zulipInit(config)`.

```js
const zulipInit = require('zulip-js');
import zulipInit from 'zulip-js';

const config = {
username: process.env.ZULIP_USERNAME,
password: process.env.ZULIP_PASSWORD,
Expand Down Expand Up @@ -57,8 +59,9 @@ site=http://localhost:9991
Please remember to add this file to your `.gitignore`! Calling `await zulipInit({ zuliprc: 'zuliprc' })` will read this file.

```js
const zulipInit = require('zulip-js');
const path = require('path');
import zulipInit from 'zulip-js';
import path from 'path';

const zuliprc = path.resolve(__dirname, 'zuliprc');
(async () => {
const zulip = await zulipInit({ zuliprc });
Expand Down Expand Up @@ -141,9 +144,9 @@ Use `npm test` to run the tests.
Currently, we have a simple testing framework which stubs our network requests and also allows us to test the input passed to it. This is what a sample test for an API endpoint looks like:

```js
const chai = require('chai');
const users = require('../../lib/resources/users'); // File to test.
const common = require('../common'); // Common functions for tests.
import chai from 'chai';
import users from '../../lib/resources/users';
import common from '../common';

chai.should();

Expand Down
2 changes: 1 addition & 1 deletion examples/accounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

process.on('unhandledRejection', (err) => {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion examples/call_endpoint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/emojis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
4 changes: 2 additions & 2 deletions examples/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const zulip = require('../lib');
import path from 'path';
import zulip from '../lib';

(async () => {
// Initialization with zuliprc
Expand Down
6 changes: 3 additions & 3 deletions examples/interactive_call_endpoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const homedir = require('os').homedir();
const zulip = require('../lib');
import path from 'path';
import { homedir } from 'os';
import zulip from '../lib';

if (process.argv[2] === 'help') {
console.log('This is a helper script to test Zulip APIs.');
Expand Down
2 changes: 1 addition & 1 deletion examples/messages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const stream = 'test-bot';

Expand Down
2 changes: 1 addition & 1 deletion examples/private-messages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
4 changes: 2 additions & 2 deletions examples/queue_helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const zulip = require('../lib');
import path from 'path';
import zulip from '../lib';

const zuliprc = path.resolve('/path/to/your/zuliprc');

Expand Down
2 changes: 1 addition & 1 deletion examples/queues.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/reactions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion examples/streams.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
4 changes: 2 additions & 2 deletions examples/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
apiKey: process.env.ZULIP_API_KEY,
realm: process.env.ZULIP_REALM,
};

const zulip = require('../lib');

(async () => {
const z = await zulip(config);

Expand Down
2 changes: 1 addition & 1 deletion examples/typing-notifications/send-and-recieve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../../lib');
import zulip from '../../lib';

if (process.argv.length < 7) {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion examples/typing-notifications/send-often.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../../lib');
import zulip from '../../lib';

if (process.argv.length < 6) {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion examples/typing-notifications/send.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../../lib');
import zulip from '../../lib';

const recipient = Number(process.env.ZULIP_TYPING_RECIPIENT);

Expand Down
2 changes: 1 addition & 1 deletion examples/users.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const zulip = require('../lib');
import zulip from '../lib';

const config = {
username: process.env.ZULIP_USERNAME,
Expand Down
Loading