From 000af6a7051e8d85431c2635a80f1537758cc76b Mon Sep 17 00:00:00 2001 From: utkarsha-deriv Date: Thu, 27 Jul 2023 14:37:16 +0400 Subject: [PATCH] feat: add line numbers to code examples --- docs/core-concepts/api-calls-anatomy/index.md | 6 +++--- .../authorization-authentication/index.md | 6 +++--- docs/core-concepts/websocket/index.md | 2 +- docs/languages/javascript/get-country-list/index.md | 8 ++++---- docs/languages/javascript/project-setup/index.md | 6 +++--- .../javascript/websocket-connection/index.md | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/core-concepts/api-calls-anatomy/index.md b/docs/core-concepts/api-calls-anatomy/index.md index d8a45ecd..4f9a5a3e 100644 --- a/docs/core-concepts/api-calls-anatomy/index.md +++ b/docs/core-concepts/api-calls-anatomy/index.md @@ -64,7 +64,7 @@ A `Residence List` call returns a list of countries and 2-letter country codes, The request data for this call is as below: -```ts +```ts showLineNumbers { residence_list: 1; // Api Call Method Name passthrough?: object; // Optional @@ -96,7 +96,7 @@ When you get the response for the call, there will be a `Field` with the same na The response for the `Residence List` call: -```js +```js showLineNumbers { echo_req: { req_id: 1, @@ -173,7 +173,7 @@ This `Field` contains the exact `Request Data` you sent to the server. This `Field` helps you determine which `message` data you're getting on the message event of the WebSocket connection. For example, your `onmessage` event handler for your WebSocket connection in `JavaScript` would be: -```js +```js showLineNumbers socket.onmessage = (event) => { const receivedMessage = JSON.parse(event.data); diff --git a/docs/core-concepts/authorization-authentication/index.md b/docs/core-concepts/authorization-authentication/index.md index 7abeed18..4df0d0da 100644 --- a/docs/core-concepts/authorization-authentication/index.md +++ b/docs/core-concepts/authorization-authentication/index.md @@ -71,7 +71,7 @@ Once a user signs up/logs in, they will be redirected to the URL that you entere The query parameters in the redirect URL are the user's accounts and their related session tokens. You can map the query parameters to an array using the following approach: -```js +```js showLineNumbers const user_accounts = [ { account: 'cr799393', @@ -88,7 +88,7 @@ const user_accounts = [ To authorise the user based on the user's **selected** account, call the [authorize](https://api.deriv.com/api-explorer#authorize) API call with the user's **selected** account **session token**: -```js +```js showLineNumbers { "authorize": "a1-f7pnteezo4jzhpxclctizt27hyeot" } @@ -96,7 +96,7 @@ To authorise the user based on the user's **selected** account, call the [author The response for the `authorize` call would be an object as below: -```js +```js showLineNumbers { "account_list": [ { diff --git a/docs/core-concepts/websocket/index.md b/docs/core-concepts/websocket/index.md index e80a431b..b3207db4 100644 --- a/docs/core-concepts/websocket/index.md +++ b/docs/core-concepts/websocket/index.md @@ -47,7 +47,7 @@ Sending a message can be done via socket.send(data). Here’s an example in `JavaScript`: -```js +```js showLineNumbers const app_id = 1089; // Replace with your app_id or leave as 1089 for testing. const socket = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${app_id}`); diff --git a/docs/languages/javascript/get-country-list/index.md b/docs/languages/javascript/get-country-list/index.md index 1e44c8c6..e60c4b02 100644 --- a/docs/languages/javascript/get-country-list/index.md +++ b/docs/languages/javascript/get-country-list/index.md @@ -17,7 +17,7 @@ You can learn more about countries [here](/docs/terminology/trading/residence-li To get a list of countries, update the open event listener using the following approach: -```js title="index.js" +```js title="index.js" showLineNumbers const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds let interval; // subscribe to `open` event @@ -38,7 +38,7 @@ websocket.addEventListener('open', (event) => { Now, update the `message` event listener to render the data: -```js title="index.js" +```js title="index.js" showLineNumbers // subscribe to `message` event websocket.addEventListener('message', (event) => { const receivedMessage = JSON.parse(event.data); @@ -58,7 +58,7 @@ websocket.addEventListener('message', (event) => { The response should be an object: -```json +```json showLineNumbers { "echo_req": { "req_id": 1, @@ -143,7 +143,7 @@ You will need detailed content about `IDV` and `ONFIDO` identity services, their Your final code will be: -```js title="index.js" +```js title="index.js" showLineNumbers const app_id = 1089; // Replace with your app_id or leave as 1089 for testing. const websocket = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${app_id}`); const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds diff --git a/docs/languages/javascript/project-setup/index.md b/docs/languages/javascript/project-setup/index.md index deeac713..e2493317 100644 --- a/docs/languages/javascript/project-setup/index.md +++ b/docs/languages/javascript/project-setup/index.md @@ -38,11 +38,11 @@ Now, open the `index.html` file or use the [Live Server Extension](https://marke Now, change the content of the files using the following approach: -```js title="index.js" -console.log("we will create our websocket connection here"); +```js title="index.js" showLineNumbers +console.log('we will create our websocket connection here'); ``` -```html title="index.html" +```html title="index.html" showLineNumbers diff --git a/docs/languages/javascript/websocket-connection/index.md b/docs/languages/javascript/websocket-connection/index.md index 5f37a8b1..147726e1 100644 --- a/docs/languages/javascript/websocket-connection/index.md +++ b/docs/languages/javascript/websocket-connection/index.md @@ -22,7 +22,7 @@ If you're not familiar with WebSockets, please check out [our documentation](/do Next, we'll create a WebSocket connection to Deriv WebSocket Server as seen below: -```js title="index.js" +```js title="index.js" showLineNumbers const app_id = 1089; // Replace with your app_id or leave as 1089 for testing. const websocket = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${app_id}`); ``` @@ -46,7 +46,7 @@ Generally, we have 4 events on `WebSocket connections`: Let's add an event listener for these events on our WebSocket connection. -```js title="index.js" +```js title="index.js" showLineNumbers // subscribe to `open` event websocket.addEventListener('open', (event) => { console.log('websocket connection established: ', event); @@ -78,7 +78,7 @@ Our WebSocket server provides [ping/pong](/api-explorer#ping) functionality. Let The `send` function on the WebSocket connection, only receives `string`, `ArrayBuffer`, `Blob`, `TypedArray` and `DataView`. You can read more about them on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send). This means, if we want to send an `object`, we have to stringify it with `JSON.stringify` first. ::: -```js title="index.js" +```js title="index.js" showLineNumbers // subscribe to `open` event websocket.addEventListener('open', (event) => { console.log('websocket connection established: ', event); @@ -95,7 +95,7 @@ websocket.addEventListener('message', (event) => { The `receivedMessage` would be an object like so: -```js +```js showLineNumbers { echo_req: { ping: 1 @@ -119,7 +119,7 @@ By default, `WebSocket connections` will be closed when no traffic is sent betwe A simple setup example would be the following: -```js title="index.js" +```js title="index.js" showLineNumbers const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds let interval; websocket.addEventListener('open', (event) => { @@ -145,7 +145,7 @@ Now, when the connection is `established`, we start sending `ping` requests with Your final code should be: -```js title="index.js" +```js title="index.js" showLineNumbers const app_id = 1089; // Replace with your app_id or leave as 1089 for testing. const websocket = new WebSocket(`wss://ws.binaryws.com/websockets/v3?app_id=${app_id}`); const ping_interval = 12000; // it's in milliseconds, which equals to 120 seconds