# downloadFileFromB64.mjs

    import isestr from './isestr.mjs'
    import isWindow from './isWindow.mjs'

    /**
     * 前端下載base64資料成為檔案
     *
     * Unit Test: {@link https://github.com/yuda-lyu/wsemi/blob/master/test/downloadFileFromB64.test.mjs Github}
     * @memberOf wsemi
     * @param {String} fileName 輸入檔名字串
     * @param {String} b64 輸入base64資料字串
     * @example
     * need test in browser
     *
     * //icon.png to base64
     * let b64=' '
     * downloadFileFromB64('icon.png',b64)
     *
     */
    function downloadFileFromB64(fileName, b64) {

        //check
        if (!isWindow()) {
            console.log('no window')
            return
        }

        //check
        if (!isestr(fileName)) {
            console.log('no filename')
            return
        }

        //tag a
        let a = document.createElement('a')
        a.href = b64
        a.download = fileName

        //download
        document.body.appendChild(a)
        a.click()
        document.body.removeChild(a)

    }

    export default downloadFileFromB64