Snippets Collections
function fetchData(success) {
    return new Promise((resolve, reject) => {
        if (success) {
            resolve("Data fetched successfully!");
        } else {
            reject("Error: Failed to fetch data.");
        }
    });
}

async function getData() {
    try {
        const result = await fetchData(true); // Change to false to test rejection
        console.log(result);
    } catch (error) {
        console.error(error);
    }
}

getData();
#!/usr/bin/env bash
#
# Returns Magento document root if sourced or prints if launched as standalone
#

mageRoot="$(dirname $(realpath "${0}"))"

while [[ ! -e ${mageRoot}/app/Mage.php && ! -e ${mageRoot}/bin/magento ]]
do
    mageRoot="$(dirname $(realpath ${mageRoot}))"
done

return "${mageRoot}" 2>/dev/null || printf '%s' "${mageRoot}" && exit
import { realpathSync as realpath, accessSync as access, existsSync as exists } from 'fs'
import { dirname } from 'path'

/**
 * IIFE to resolve Magento document root
 * @returns <string> Returns Magento document root
 */
export const mageRoot = (() => {
    let mageRoot = dirname(realpath(import.meta.url.slice(7)))

    while (!(exists(`${ mageRoot }/app/Mage.php`) || exists(`${ mageRoot }/bin/magento`))) {
        mageRoot = dirname(mageRoot)
    }

    return mageRoot
})()
<?php

$mageRoot = __DIR__;

while (!(file_exists($mageRoot . '/app/Mage.php') || file_exists($mageRoot . '/bin/magento'))) {
    $mageRoot = dirname($mageRoot);
}

return $mageRoot;
star

Tue Mar 11 2025 22:00:56 GMT+0000 (Coordinated Universal Time)

#async #await #resolve #reject
star

Sat Jan 08 2022 06:07:58 GMT+0000 (Coordinated Universal Time) https://gist.github.com/juliyvchirkov/2c5c8d54b182528e39d4565d1632f8ee#file-magentodocumentroot-sh

#bash #magento #document_root #resolve #shell
star

Sat Jan 08 2022 06:00:50 GMT+0000 (Coordinated Universal Time) https://gist.github.com/juliyvchirkov/2c5c8d54b182528e39d4565d1632f8ee#file-magentodocumentroot-mjs

#javascript #nodejs #magento #document_root #resolve #module #mjs
star

Sat Jan 08 2022 05:57:18 GMT+0000 (Coordinated Universal Time) https://gist.github.com/juliyvchirkov/2c5c8d54b182528e39d4565d1632f8ee#file-magentodocumentroot-php

#php #magento #document_root #resolve #module #include

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension