我正在尝试合并两个对象并覆盖进程中的值.
是否可以使用下划线执行以下操作?(我没有使用下划线,我只是希望它很简单)
var obj1 = {
"hello":"xxx"
"win":"xxx"
};
var obj2 = {
"hello":"zzz"
};
var obj3 = merge(obj1, obj2);
/*
{
"hello":"zzz",
"win":"xxx"
}
*/
Run Code Online (Sandbox Code Playgroud) 我想定义.exampleclass img {height:250px}是否启用了javascript.他们无论如何要在javascript/jquery中撤消这个?
我需要在项目中使用javascript文件作为依赖项.它没有github存储库,它不是凉亭,或者是npm,它只是住在这里.
http://a.klaviyo.com/media/js/learnmarklet.js
我可以用凉亭安装它:
bower install http://a.klaviyo.com/media/js/learnmarklet.js --save
Run Code Online (Sandbox Code Playgroud)
我知道它会在我的项目中生活:
./bower_components/learnmarklet/index.js
Run Code Online (Sandbox Code Playgroud)
我知道它附加了一个调用_learnq全局窗口对象的变量.
我想要的只是这个.
var _learnq = require("klaviyo")
Run Code Online (Sandbox Code Playgroud)
我需要别名klaviyo这样的东西.
{
"klaviyo": "./bower_components/learnmarklet/index.js"
}
Run Code Online (Sandbox Code Playgroud)
并且"shim" _learnq像这样导出变量.
{
"klaviyo": "_learnq"
}
Run Code Online (Sandbox Code Playgroud)
我怎么能用webpack做到这一点?
这就是我尝试过的,这就是我的webpack.config.js样子.
module.exports = {
resolve:{
alias:{
"klaviyo": "./bower_components/learnmarklet/index.js"
}
},
externals: {
klaviyo: "_learnq"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个带有_.combinations三个参数的函数(下划线mixin)arr, pockets, duplicates.这是我设计用于展示行为应该如何的测试.
expect(_.combinations([1, 2], 1, false)).to.be.equal([[1],[2]])
expect(_.combinations([1, 2], 1, true)).to.be.equal([[1],[2]])
expect(_.combinations([1, 2, 3], 2, false)).to.be.equal([[1,2],[1,3],[2,3]])
expect(_.combinations([1, 2, 3], 2, true)).to.be.equal([[1,2],[1,3],[2,3],[2,1],[3,1],[3,2]])
expect(_.combinations([1, 2, 3, 4], 3, false)).to.be.equal([[1,2,3],[1,2,4],[1,3,4],[2,1,4],[2,3,4],[3,4,1]])
expect(_.combinations([1, 2, 3, 4], 3, true)).to.be.equal([[1,2,3],[1,2,4],[1,3,4],[2,1,4],[2,3,1],[2,3,4],[3,1,2],[3,4,1],[3,4,2],[4,1,2],[4,1,3],[4,2,3]])
Run Code Online (Sandbox Code Playgroud)
在我去创建这个函数之前,我想知道它是否已经存在于库中.也许这个特定的功能已经有了一个我不熟悉的名字.
那里有什么东西吗?
我正在学习Ramda,我有点困惑如何在lodash下面使用构建这个链Ramda.Ramda返回它的操作而不是实际值的函数,这似乎是函数式编程的焦点,但是在这个例子中我有第二个参数localRegex不是主要参数.似乎在没有包装Ramda函数和使用.apply()或.call()将包装的函数参数传播给函数的情况下完全复制它是不可能的Ramda,这似乎比使用更复杂lodash.
var _ = require("lodash")
var R = require("ramda")
var localRegex = /^.\.\/|^.\/|^\//
function getRecursiveDeps(deps, localRegex){
return _.chain(deps)
.map(function(dep){
return dep.source.value
})
.filter(function(dep){
return dep.match(localRegex)
})
.value()
}
var items = [
{
"source": {
"value": "./foo"
}
},
{
"source": {
"value": "bar"
}
}
]
console.log(getRecursiveDeps(items, localRegex))
Run Code Online (Sandbox Code Playgroud)
这是我得到的,它不起作用.
var getRecursiveDeps = R.chain(
R.map(function(dependency){
return dependency.source.value
}),
R.filter(function(value){
return …Run Code Online (Sandbox Code Playgroud) javascript dictionary functional-programming lodash ramda.js
我编写了下面的函数来返回与特定模式匹配的对象中的所有键.它看起来真的很圆,因为在lodash对象中没有过滤器功能,当你使用它时,所有的键都会丢失.这是使用lodash过滤对象键的唯一方法吗?
export function keysThatMatch (pattern) {
return (data) => {
let x = _.chain(data)
.mapValues((value, key) => {
return [{
key: key,
value: value
}]
})
.values()
.filter(data => {
return data[0].key.match(pattern)
})
.zipWith(data => {
let tmp = {}
tmp[data[0].key] = data[0].value
return tmp
})
.value()
return _.extend.apply(null, x)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在努力将以下字符串分成两部分.主要是因为可能的分隔符之一是空格字符,它可以出现在第二个捕获组中.
https://regex101.com/r/dS0bD8/1
我怎样才能在任拆分这些字符串\s,\skeyword\s或\skey\s?
'[] []' // => ['[]', '[]']
'[] keyword []' // => ['[]', '[]']
'[] key []' // => ['[]', '[]']
'[] ["can contain spaces"]' // => ['[]', '["can contain spaces"]']
'[] keyword ["can contain spaces"]' // => ['[]', '["can contain spaces"]']
'[] key ["can contain spaces"]' // => ['[]', '["can contain spaces"]']
'{} {}' // => ['{}', '{}']
'{} keyword {}' // => ['{}', '{}']
'{} key {}' // => ['{}', …Run Code Online (Sandbox Code Playgroud) 在terraform文档中,它显示了如何使用模板.有没有办法将此渲染输出记录到控制台?
https://www.terraform.io/docs/configuration/interpolation.html#templates
resource "template_file" "example" {
template = "${hello} ${world}!"
vars {
hello = "goodnight"
world = "moon"
}
}
output "rendered" {
value = "${template_file.example.rendered}"
}
Run Code Online (Sandbox Code Playgroud) 我想nyc ava和babel所有人在一起好好相处.我有一个问题,async/await分支显示为未覆盖,所以这是有效的,我无法集成babel-plugin-istanbul插件进行测试.
我在项目中有两个文件,src/index.js和src/test.js.
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "ava",
"coverage": "NODE_ENV=test nyc npm run test",
"report": "nyc report --reporter=html",
"report:open": "open ./coverage/index.html",
"cover": "npm run coverage && npm run report && npm run report:open"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-runtime": "^6.26.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"ava": "^0.22.0",
"babel-cli": "^6.26.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-register": …Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能给一个具有导出类型的文件,这些类型是否可以从泛型中提取到计算类型?
function example() {
return {
foo: 'hi',
bar: true,
baz: 1
};
}
export type Signature = ReturnType<typeof example>;
Run Code Online (Sandbox Code Playgroud)
对此:
export type Signature = {
foo: string;
bar: boolean;
baz: number;
}
Run Code Online (Sandbox Code Playgroud)
我不相信tsccli会这样做,我不确定这个过程会被称为什么。
可以tsc创建这个导出吗?
有没有第三方工具可以做到这一点?
我知道如何做到这一点的唯一方法是将鼠标悬停在 VSCode 中的变量上并复制计算类型,并且只有在它很短并且不会减弱时才有效......
我发现了其他一些对类似请求的引用:
javascript ×7
lodash ×2
arrays ×1
ava ×1
babel ×1
dictionary ×1
istanbul ×1
jquery ×1
nyc ×1
probability ×1
ramda.js ×1
regex ×1
sorting ×1
terraform ×1
typescript ×1
webpack ×1