eval( pm.globals.get('pmlib_code') ); var CryptoJS = require("crypto-js"); getHash=(request)=>{ return CryptoJS.enc.Base64.stringify(CryptoJS.SHA256(request)); } signData=(data, privateKey)=> { var sig = new pmlib.rs.KJUR.crypto.Signature({"alg": "SHA256withRSA"}); sig.init(privateKey); var encrypted = sig.signString(data); const signedEncoded = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(encrypted)); return signedEncoded; } var strinToSign ='15FISCALINVOICEUSD252023-07-14T11:03:5192000015.00120000920000t/S6i/KGMEsTS7CLYeXvVQ9RaKuu7SY0nsRWz44Bm0o=' var hash = getHash(strinToSign); var privateKey = `-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8prNStxE93Isb 6/6ZsJAf8Mjy9OctbLUnhS16vldNoIThOO5smOJ93NWNIP66P3Pj3gzJ7dt6cAWS aYCSc8awZf86ax7cwTLWS67ip75mGkOQG4TBN3UzVcYRo/JYFlcbZDLNpVVfTodC nQ7gnKG0byxV9BbNAHuegGGXRajuU7w1++mDY3IzeInf+2BCByJFlFqu0yahAPjU daEk0/gOrCO+BCzQRaGM7GlJZ3lPIz/RH7SKMDfPGU4Gtt0JXe/ImtbFu2JH7aUK dmmqqYAhE0LL6XFmsT3oH3jx4m5NYe/WZ7Qz5IfwYi2TB4ieGdbzZVv7ktIF5lZ+ ro621k9fAgMBAAECggEAC0T+E2PiQMrK+JkJdY7pnS7aIkFlCf6jd7/p7pouRvHe 3kFzZMNhTFmD3FFrRh8CQkuCghGWeeL1QkDRMG6AIQuGyquZhWB5M/oDcYDJy/mn rZUnQg+ZDb8C/QzJLl/vRjCfJE/LIM1lISKWv+47brbxdBUHw6lSuS48JjhAFjSK GPNzbLr+ZhJZLvfRXpLWZrU+JeGhO1bcOa5kpVyq/cd1GYqH9A22bZfJikiF8+3C aAlMN8pQmvx6dZmX+Q0xHQat7gWDF7A9WS6k+zA8Agcw5uDf+l0o5/aEmjzKAv3B co3lXLJdS7A4gvLhxPMnMzqjLEQvnqV24asHJAEzwQKBgQDdlh7i1ZnOysFPK+Qn 83SodXNbGkMWJiwhkABT2HsSzrsSqg8WTeRCLxF662k/j6YjSEO00OhbQe1pZPUB cHI0BLcdOBze/5KizUOkAHcHniGS4pTa/WLlc0b3b2UVKEJBPB/guGxHcEzi4UiF EtacFCsROxRiSxTQb07ZQsb5vwKBgQDZ8yI/wIbuu8bn9wyrkCTzNKfoCC+bf/28 4UmI8xHsvYaOGlMFNU7V9pdPRRNUuW0ibtqLMaDD8f8jNFtrm7jIw3ID66+ScJ0d epl9Byq98CGwCaW+znRic/fKXqFtTKJd9QTOq4yF8MfsQsEf7x4UM6f9RYnBm8C/ 2xFzNi3SYQKBgFFtQA5VNf8izOSeGWqA8WaSOoDI5sw13NO8ihJFo/xmUaJrMb4d g3q6ty63YWbFD+U5QgApIKmgUXEAc3RC8QSikvO+0gU0X5tJ2Mhkj1kSR/4lG1RZ 9sSglvyIR9n9gFNel8xJmSirYOWiqbaVFJ4oXycm0bfJJW3u6Ue3XU0bAoGANMK3 4sj/oSFR6GuU5J9TYpC3qOL6a2FTknrTK1T0XOQQg6v5twQNnpxASs9E+7ibo79E JngQG/8kLWiKTQV4eRlfK3XNndynHDDGoU6v2SUdcpkTR5qA8Ch0rsezulrX33jl /gXnUbFVJGuQhuOC248ZtqUz0OucgJVOpx5Rf2ECgYBGCrwbZfMd1Gkv9UA5sQCC Vi8F0uh4UbZtBid75gf8aBS4gvs1fqxMOhc76XkcWVJ8wJ7mDKET8zWxOZZYODOl X72G+cigdGeiH67b6OEYTyUSsJWc+Jp97wKMfarSM3zq9WJ9Evyv9Edhomb4y7jK 499vLNeBYn8ynBne4WPZrQ== -----END PRIVATE KEY-----` var signature = signData(strinToSign, privateKey);
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");