小编Cou*_*eau的帖子

如何使用 fetch polyfill、rollup 和 typescript 创建 umd 包?

我正在尝试将库与汇总捆绑在一起。

\n

在这个库中,我正在发出 http 请求。\n我想使用fetch并在代码在节点上运行时使用 polyfill。\n我无法获得正确的配置。\n它可以在节点上运行,但不能在浏览器,或相反。

\n

这是我的配置文件的样子:

\n
 module.exports = [{\n    input: \'src/mylibrary.ts\',\n    output: {\n      name: LIB_NAME,\n      file: getOutputFileName(\n        resolve(ROOT, pkg.browser),\n        env === \'production\'\n      ),\n      format: \'umd\',\n      globals: {\n        fetch: \'cross-fetch\',\n      },\n    },\n    plugins: [\n     typescript({\n      useTsconfigDeclarationDir: true,\n      tsconfigOverride: {\n        allowJs: false,\n        includes: [\'src\'],\n        exclude: [\'tests\', \'examples\', \'*.js\', \'scripts\'],\n        esModuleInterop: true,\n      },\n     }),\n      nodeResolve({\n        mainFields: [\'jsnext\', \'main\'],\n        preferBuiltins: true,\n        browser: true,\n      }),\n      commonjs({\n        include: [\'node_modules/**\'],\n      }),\n      json(),\n      env === \'production\' ? terser() : {}, // will minify …
Run Code Online (Sandbox Code Playgroud)

javascript rollup typescript

5
推荐指数
1
解决办法
1571
查看次数

如何将多个零推送到已经存在的数组

我在此链接上找到了如何创建具有选定数量的零的数组。 创建零填充 JavaScript 数组的最有效方法?

但我的问题是,想象我已经有一个数组

var a = ['hihi','haha']
Run Code Online (Sandbox Code Playgroud)

如何在我的两个第一个元素后添加 12 个零?所以它变成:

a = ['hihi','haha',0,0,0,0,0,0,0,0,0,0,0,0];
Run Code Online (Sandbox Code Playgroud)

我当然可以去

for(var i = 0; i < 12, i++){
  a.push(0);
}
Run Code Online (Sandbox Code Playgroud)

但是有一种单行方法吗?就像是

a.push(6*[0]);
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

3
推荐指数
1
解决办法
1690
查看次数

SimpleHTMLDom:调用数组中的成员函数find()

所以我想在特定TD的html页面中循环特定的低谷。我正在使用simplehtmldom来实现这一目标。问题是,如果不将所有步骤都放在foreach中,我将无法使其工作。

这是我的PHP

include('../inc/simple_html_dom.php');
$html = file_get_html("http://www.bjork-family.com/f43-london-stories");
// I just put the dom of pagebody into TEST
$test =  $html->find('#page-body');
foreach($test->find('img') as $element) 
{
    echo "<img src='" . $element->src . "'/>" . '<br>';
}
Run Code Online (Sandbox Code Playgroud)

我得到这个错误

Fatal error: Call to a member function find() on array in /mywebsite.php on line 39
Run Code Online (Sandbox Code Playgroud)

39行就是这个

foreach($test->find('img') as $element) 
Run Code Online (Sandbox Code Playgroud)

我尝试了很多不同的方法,如果我真的很简单的话:

// Create DOM from URL or file
$html = file_get_html('http://www.bjork-family.com/f43-london-stories');
foreach($html->find('img') as $element) 
       echo $element->src . '<br>'; 
Run Code Online (Sandbox Code Playgroud)

然后就可以了!

所以当我这样走时似乎正在工作

foreach($html->find('div') as $element) 
    {
        if($element->id …
Run Code Online (Sandbox Code Playgroud)

php simple-html-dom

3
推荐指数
1
解决办法
2417
查看次数

在Ubuntu中使用正则表达式查找文件

我有一个任务,我必须找到条件,我认为需要正则表达式的不同文件.

例如 :

查找以3个小写字母开头且最后一个字母不是"i"的文件.我正在寻找找到这些文件的最佳方法.

我可以

ls [a-z][a-z][a-z]*[azertyuopqsdfghjklmwxcvbn]
Run Code Online (Sandbox Code Playgroud)

但是,这似乎有点.有任何想法吗 ?

regex linux ubuntu grep

2
推荐指数
1
解决办法
2662
查看次数

等待/异步匿名功能

我试图在匿名函数上使用await这是结果:

这是有效的方式

async function hello(){
    return "hello";
}
let x = await hello();
console.log(x);
Run Code Online (Sandbox Code Playgroud)

结果:

“你好”

这是我希望它工作的方式:

let x = await async function() {return "hello"};
console.log(x);
Run Code Online (Sandbox Code Playgroud)

结果:

[AsyncFunction]

我想念什么?我是新来的诺言。

编辑: 我试图添加匿名函数后调用()。这是带有实际异步代码的示例:

let invitationFound = await (async function (invitationToken, email){
    return models.usersModel.findOneInvitationByToken(invitationToken, email)
        .then(invitationFound => {

            return  invitationFound;
        })
        .catch(err =>{
           console.log(err);
        });
})();

console.log(invitationFound);
return res.status(200).json({"oki " : invitationFound});
Run Code Online (Sandbox Code Playgroud)

console.log的结果:

ServerResponse {域:null,_events:{完成:[Function:绑定resOnFinish]},_eventsCount:1,_maxListeners:未定义,输出:[],outputEncodings:[],..

res.code的结果

handlePromiseRejectionWarning:TypeError:将圆形结构转换为JSON

我不认为该错误来自models.usersModel.findOneInvitationByToken,因为在我的第一种情况下使用它时效果很好

let userFound = await test(invitationToken, email);
Run Code Online (Sandbox Code Playgroud)

编辑2:

我发现了第二个问题!我忘了把参数放在括号里

let invitationFound = await (async function (invitationToken, …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js async-await es6-promise

1
推荐指数
1
解决办法
4482
查看次数