Use Javascript Libary On Typescript Project

I want to use an payment system which is calling iyzico.
The iyzico payment library is https://www.npmjs.com/package/iyzipay it. But there is not any types so how can i use this library on my node.js typescript express backend project?

i tried make one mylib.d.ts file on my root directory and put this code on this file.

declare module 'iyzipay';

After then i put this variable on my tsconfig.json file

  ,"include": [
    "src", "mylib.d.ts"
  ]

When i import the libary on my project i get an error like this.

Could not find a declaration file for module ‘iyzipay’. ‘/Users/xxx/node_modules/iyzipay/lib/Iyzipay.js’ implicitly has an ‘any’ type.
Try npm i --save-dev @types/iyzipay if it exists or add a new declaration (.d.ts) file containing `declare module ‘iyzipay’;

JQuery dropdown toggle not working on mobile but works perfect locally

I have a nav menu with dropdown lists. When running locally and clicking the element the dropdown menu list appears perfect. When actually attempting on a mobile device it does nothing. Any suggestions why this maybe happening and how to fix?

Worth noting I am injecting the header via JQuery – see screenshot below

Feel free to demo at http://credit.fleetfactors.co.uk, try on desktop, mobile and desktop (inspect as mobile device)…

Scripts

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="static/js/jquery-3.5.1.min.js"></script>
<script src="static/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="static/vendor/counter/jquery.countTo.js"></script>
<!-- typed -->
<script src="static/vendor/typed/typed.js"></script>
<!-- owl-carousel -->
<script src="static/vendor/owl-carousel/js/owl.carousel.min.js"></script>
<!-- magnific -->
<script src="static/vendor/magnific/jquery.magnific-popup.min.js"></script>
<script src="static/vendor/isotope/isotope.pkgd.min.js"></script>
<!-- svg-injector -->
<script src="static/vendor/svginjector/svg-injector.min.js"></script>
<!-- jarallax -->
<script src="static/vendor/jarallax/jarallax-all.js"></script>
<!-- count-down -->
<script src="static/vendor/count-down/jquery.countdown.min.js"></script>
<!-- working form -->
<script src="static/vendor/mail/js/form.min.js"></script>
<script src="static/vendor/mail/js/script.js"></script>

JQuery

   CRE.MegaMenu = function() {
        var mDropdown = $(".px-dropdown-toggle") 
        mDropdown.on("click", function() {
            $(this).parent().toggleClass("open-menu-parent");
            $(this).next('.dropdown-menu').toggleClass("show");
            $(this).toggleClass("open");
        });
    }

Html (index.html)

<!-- Header -->
    <header id="main-header" class="header-main header-dark fixed-top header-fluid">
        <script>
   fetch('/includes/header.html')
  .then(response => response.text())
  .then(value => {
    document.getElementById('main-header').innerHTML = value
  });
        </script>
    </header>
<!-- Header End -->

Includes (header.html)

<div class="header-top header-border-bottom small">
    <div class="container">
        <div class="d-flex justify-content-between align-items-center">
            <!-- Left -->
            <div class="d-flex align-items-center justify-content-center d-none d-lg-block">
                <ul class="nav">
                    <li class="nav-item me-3 text-white">
                        <span>
                            <i class="fa fa-envelope me-2"></i>
                            Email: [email protected]
                        </span>
                    </li>
                    <li class="nav-item">
                        <a href="#" class="navbar-link text-white">
                            <i class="fas fa-headset me-2"></i>
                            Call: 01642 770 664
                        </a>
                    </li>
                </ul>
            </div>
            <!-- Right -->
            <div class="d-flex align-items-center justify-content-center w-100 w-lg-auto">
                <!-- Language -->
                <div class="dropdown ms-0 ms-lg-3">
                    <a class="dropdown-toggle text-white" href="#" role="button" id="dropdown_language" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa-fw me-2 bi bi-globe"></i>Global</a>
                    <div class="dropdown-menu mt-2 shadow" aria-labelledby="dropdown_language" style="margin: 0px;">
                        <span class="dropdown-item-text">Select Site</span>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#"><i class="fa-fw me-2 bi bi-cart4"></i> Fleet Shop</a>
                        <a class="dropdown-item" href="#"><i class="fa-fw me-2 bi bi-upc-scan"></i> E-Cat</a>
                                               </div>
                </div>
                <!-- Top link -->
                <ul class="nav ms-auto ms-lg-3">
                    <li class="nav-item">
                        <a href="/contact-us.html" class="nav-link text-white">Contact</a>
                    </li>
                    <li class="nav-item">
                        <a href="/downloads.html" class="nav-link text-white" data-bs-toggle="modal" data-bs-target="#topbarlogin"><i class="fa-solid fa-folder-open me-2"></i>Downloads</a>
                    </li>
                </ul>
                <!-- Top social -->
                <div class="nav header-social justify-content-end d-none d-lg-block">
                    <a class="h-social-link" href="#"><i class="bi bi-facebook"></i></a>
                    <a class="h-social-link" href="#"><i class="bi bi-twitter"></i></a>
                    <a class="h-social-link" href="#"><i class="bi bi-linkedin"></i></a>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Top Header -->
<nav class="navbar navbar-expand-lg navbar-dark">
    <div class="container">
        <!-- Logo -->
        <a class="navbar-brand" href="index.html">
            <img class="logo-dark" src="/static/img/fleet-logo-dark.svg" width="160px" title="" alt="">
            <img class="logo-light" src="/static/img/fleet-logo-light.svg" width="160px" title="" alt="">
        </a>
        <!-- Logo -->
        <!-- Mobile Toggle -->
        <button class="navbar-toggler ms-auto me-2" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <!-- End Mobile Toggle -->
        <!-- Menu -->
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav m-auto">

                <li class="nav-item">
                    <a href="https://fleetfactors.co.uk" class="nav-link">
                       Home
                    </a>
                </li>

                <li class="dropdown nav-item">
                    <a href="#" class="nav-link">Company</a>
                    <label class="px-dropdown-toggle mob-menu"></label>
                    <ul class="dropdown-menu left list-unstyled">
                        <li><a class="dropdown-item" href="/company/about-us.html">About Us</a></li>
                        <li><a class="dropdown-item" href="/company/team.html">Our Team</a></li>
                        <li><a class="dropdown-item" href="/company/corporate-social-values.html">Corporate Social Values</a></li>
                        <li><a class="dropdown-item" href="/company/qhse.html">QHSE</a></li>
                        <li><a class="dropdown-item" href="/careers.html">Careers</a></li>
                        <li><a class="dropdown-item" href="/news.html">News & Events</a></li>
                    </ul>
                </li>

                <li class="dropdown nav-item">
                    <a href="#" class="nav-link">Services</a>
                    <label class="px-dropdown-toggle mob-menu"></label>
                    <ul class="dropdown-menu left list-unstyled">
                        <li><a class="dropdown-item" href="/brands.html">Brands</a></li>
                        <li><a class="dropdown-item" href="/services/stores-management.html">Stores Management</a></li>
                        <li><a class="dropdown-item" href="/services/commercial-parts.html">Bus, Truck & Trailer Parts</a></li>
                        <li><a class="dropdown-item" href="/services/consumables.html">Consumables</a></li>
                        <li><a class="dropdown-item" href="/services/lubricants.html">Lubricant Products</a></li>
                        <li><a class="dropdown-item" href="/services/refinish.html">Refinish Products</a></li>
                        <li><a class="dropdown-item" href="/services/ppe.html">PPE Products & Embroidery</a></li>
                        <li><a class="dropdown-item" href="/services/janitorial.html">Janitorial Products</a></li>
                    </ul>
                </li>


                <li class="dropdown nav-item">
                    <a href="#" class="nav-link">Resources</a>
                    <label class="px-dropdown-toggle mob-menu"></label>
                    <ul class="dropdown-menu left list-unstyled">
                        <li><a class="dropdown-item" href="/resources/brand-guidelines.html">Brand Guidelines</a></li>
                        <li><a class="dropdown-item" href="/resources/promotions.html">Promotions</a></li>
                        <li><a class="dropdown-item" href="/resources/brochures.html">Brochures</a></li>
                        <li><a class="dropdown-item" href="/resources/accreditations.html">Accreditations</a></li>
                    </ul>
                </li>

                <li class="dropdown nav-item">
                    <a href="#" class="nav-link">Support</a>
                    <label class="px-dropdown-toggle mob-menu"></label>
                    <ul class="dropdown-menu left list-unstyled">
                        <li><a class="dropdown-item" href="/support/returns-policy.html">Returns</a></li>
                        <li><a class="dropdown-item" href="/support/delivery-policy.html">Delivery</a></li>
                        <li><a class="dropdown-item" href="/branch-locator.html">Branch Locator</a></li>
                        <li><a class="dropdown-item" href="/contact-us.html">Contact Us</a></li>
                    </ul>
                </li>

                           
            </ul>
        </div>
        <!-- End Menu -->
        <div class="nav flex-nowrap align-items-center">
            <!-- Nav Search-->
            <div class="nav-item">
                <a class="nav-link pe-0 collapsed display-7 py-0 me-3" data-bs-toggle="collapse" href="javascript:void(0)" data-bs-target="#search-open" aria-expanded="false">
                    <i class="bi bi-search display-8"> </i>
                </a>
            </div>
            <!-- Nav Button -->
            <div class="nav-item d-none d-xl-block">
                <a href="#" class="btn btn-sm btn-outline-fleet mb-0 mx-2 text-nowrap">Login to Fleet Shop<i class="bi bi-arrow-right-short ms-2"></i></a>
            </div>
        </div>
    </div>
</nav>

When testing component throwing error actually throws it instead of passing the test

This is my test:

  it("should throw an error", async () => {
    expect(() =>
      render(
        <Provider store={store}>
          <DefinitionEditorForm mode="edit" definitionId={undefined} />
        </Provider>
      )
    ).toThrow("Can't edit existing document definition");
  });

Basically, rendering the DefinitionEditorForm should throw an error if the mode is edit and the definitionId is undefined.

const loadDefinitionToEdit = async () => {
    if (definitionId) {
      try {
        const definition = await dispatch(fetchDefinitionById(definitionId)).unwrap();
        setInitialValues({ displayName: definition?.displayName ?? "" });
      } catch (e) {
        onClose && onClose();
      }
    } else {
      throw new Error("Can't edit existing document definition"); <<<< it ends up here
    }
  };

It ends up on the throw new Error() line. And it does this because this is the output of my test:

src/app/features/documents/definitions/DefinitionEditorForm/DefinitionEditorForm.test.tsx
/Users/user/workspace/work/ui/src/app/features/documents/definitions/DefinitionEditorForm/DefinitionEditorForm.tsx:55
            throw new Error("Can't edit existing document definition");
                  ^

... stack trace

And it literally also exits the test watching state. So I have to restart it, and of course it just fails again.

Any idea what I could be doing wrong?

How do i put the sl. no. in table while using {{#each}} loop in handlebars

I am creating a table to show list of items from the database, but how do I put the serial No. for the list when using a {{#each}} loop:

 <table class="table mt-5">
        <thead>
            <tr>
                <th scope="col">No.</th>
                <th scope="col">Title</th>
                <th scope="col">Category</th>
                <th scope="col">Description</th>
                <th>Image</th>
            </tr>
        </thead>
        <tbody>
            {{#each products}}
            <tr>
                <th scope="row">1</th>
                <td>{{this.Name}}</td>
                <td>{{this.Category}}</td>
                <td>{{this.Description}}</td>
                <td><img  style="width:100px" src="/product-images/{{this._id}}.png" alt="Img"></td>
            </tr>
            {{/each}}
        </tbody>
    </table>       

This is the table I am using, In the th tag I have written 1, I want to replace it with the sl. no. This is a .hbs file and i am using Node.js and MongoDB as database
How will I do it?

JQuery How to get JSON value by key name

I want to translate from JSON file by html attribute

get JSON value like translate attribute and “ed” key

JSON FILE

{
"open" : [
    {
        "en": "Open",
        "ed": "Opened"
    }
],

"close" : [
    {
        "en": "Close",
        "ed": "Closed"
    }
]

}

HTML

<p translate="open"></p>

JQuery

var word = $("p");
var wordA = $("p").attr("translate"); // open

$.getJSON('language.json', function(data) {
        
    $.each(data, function(key, val) {

        if (key === wordA) {
           word.html(val.ed);
           // result opened
         }

    });

});

How to calculate SHA512 in csharp properly

I have in postman prerequest script like this one:

var originalHashSalt = "secret-string";

var b = pm.request.body.toString();

var hash = CryptoJS.SHA512(originalHashSalt + b).toString();

This is being used to set Authiorization header in request.

Now I find some implementation of this in csharp but tests fail. Not quite sure what may be the reason but charp implementation looks like this:

 var originalHashSalt = "242a777e-914d-45a0-97ad-2036b7148c6c";
            // var b = pm.request.body.toString();
            //
            var source = originalHashSalt + JsonConvert.SerializeObject(order, Formatting.None);
            var data = Encoding.UTF8.GetBytes(source);
            string actual;
            using (SHA512 shaM = new SHA512Managed())
            {
                var hash = shaM.ComputeHash(data);
                actual = ByteArrayToString(hash).ToLowerInvariant();
            }

 private static string ByteArrayToString(byte[] ba) => BitConverter.ToString(ba).Replace("-", "");

And unfortunately output result is not the same as JavaScript implementation above.

Any hint what I am missing here?

Many thanks

ZK: dom-to-image screenshot script not working?

Hi I am new to ZK and I am struggling to get my script working. I have tried creating testing the script on a HTML page which worked fine but it does not work in my ZK page

<script>
   function captureScreen() {
      const screenshotTarget = document.body;
     
      domtoimage.toBlob(screenshotTarget).then(function (blob) { window.saveAs(blob, 'my-node.png'); });
      alert("alert box!!");
   }
</script>

the alert box was added as a test and it displays fine, however the script to take and download a screen capture does not.

2D array as return value from ajax

I am not only new here, but also a total beginner in programming.
I have programmed a small web application that uses “Ajax” to update data in the front panel. The first version works, but is very cumbersome and also takes a long time.

function updateAll(article){
                document.getElementById("artnr").value = article.options[article.selectedIndex].text;
                document.getElementById("SaveMessage").innerHTML = "";
                
                // 1. Anzahl der Aufträge ermitteln
                $.ajax({
                    type: 'GET',
                    url: 'cntOrder.php',
                    data: $(article),
                    success: function(data){document.getElementById("cntOrder").value = data;}
                });

                // 2. Median aller Uem-Werte
                $.ajax({
                    type: 'GET',
                    url: 'setPoint.php',
                    data: $(article),
                    success: function(data){document.getElementById("setPoint").value = data; calcTarLim(data);}
                }); // Aufruf 4. über "calcTarLim()"
                
                // 3. Aktuelle Grenze auslesen
                $.ajax({
                    type: 'GET',
                    url: 'curLim.php',
                    data: $(article),
                    success: function(data){document.getElementById("curLim").value = data;}
                });

                // 5. Graph aktualisieren (Messwerte, currentLimit und targetLimit)
            }
            
            // 4. Zielwert für Grenze berechnen
            function calcTarLim(data){
                let tol = parseFloat(document.getElementById("tolLim").value);
                let soll = 0;
                if(data == 'change'){
                    window.alert("if: " + data);
                } else {
                    soll = parseFloat(data);
                }
                let ziel = soll * ((100-tol)/100);
                ziel = ziel.toFixed(2);
                document.getElementById("tarLim").value = ziel;
            }

Now my idea was to handle all queries in one Ajax query and put the different return values in an array and then evaluate them using the keys.
Unfortunately I don’t get any values out.

function updateAll(article){
                document.getElementById("artnr").value = article.options[article.selectedIndex].text;
                document.getElementById("SaveMessage").innerHTML = "";
                
                // 1. Ajax Aufruf, Datenbankfunktionen
                $.ajax({
                    type: 'GET',
                    url: 'ajax.php',
                    data: $(article),
                    success: function(data){
                        window.alert(data);
                        document.getElementById("cntOrder").value = data['cntOrder']['cnt'];
                        document.getElementById("setPoint").value = data['setPoint'];
                        document.getElementById("curLim").value = data['CurLim']['uemmin'];
                        calcTarLim(data['setPoint']);
                    }
                });

Data looks like this:

Array
(
    [cntOrder] => Array
        (
            [cnt] => 6
        )

    [curLim] => Array
        (
            [uemmin] => 16.00
        )

    [setPoint] => 26.28
)

Thanks in advance for any help. If more data is needed, I will of course add it.

element.nextSibling returns first sibling

So I have a Vue app, with HotJar included.
Everything used to work fine but then I upgraded some packages
Now when I navigate between pages, my browser freezes and then crashes
After a little bit of investigation, I noticed that it’s getting stuck in HotJar’s code.
They have this little loop that iterate on siblings using

for (let f = someElement; !!f; f = f.nextSibling) { 
  //Some code
}

The problem is that somehow, when it iterates over elements, sometime nextSibling returns the first sibling which is extremely odd and results in an infinite loop.

Anyone has any clue how can I proceed from this?
Changing the code to nextElementSibling from nextSibling solves the issue, but this call is inside HotJar code and I really rather not download and change their code

Js Regex Match conditional EOL

How do I check for a charackter only allowed if the String doesnt end?

e.g. comma seperated Lists

  • 041 => true
  • 041,021 => true
  • 041, 021 => true
  • 041, => false

and so on

I thought it should be something like

([0-9]{3},?!$)+

But that wont match anything.

remove white background from dragImage

I’ve a draggable element and whenever I drag that from a dark background, it shows the white outline. To solve this, I’ve set a custom color DIV as setDragImage thinking that would solve the issue somehow but no help. Is there a way or hack to remove it completely?

Here’s how it looks like:

enter image description here

Here’s my code:

document.addEventListener("dragstart", (e) => {
    const ghost = document.createElement("div");
    // I've used Tailwind, btw....
    ghost.className = "bg-indigo-500 h-[30px] w-[100px] drop-shadow-md";
    document.body.appendChild(ghost);

    const dt = e.dataTransfer;
    dt.setDragImage(ghost, 0, 0);
  });