Skip to content

Instantly share code, notes, and snippets.

@s3rgeym
Created June 16, 2019 17:20
Show Gist options
  • Save s3rgeym/e79120e911330f2fa0fc02a71c68c2a0 to your computer and use it in GitHub Desktop.
Save s3rgeym/e79120e911330f2fa0fc02a71c68c2a0 to your computer and use it in GitHub Desktop.
function query(strings, ...values) {
  return strings.slice(1).reduce((acc, v, i) => acc + JSON.stringify(values[i]) + v, strings[0])
}
undefined
var username = 'j.doe'
undefined
var password = 'asd123'
undefined
query`
  mutation {
    authenticate(username: ${username}, password: ${password}) {
      token
    }
  }
`
"
  mutation {
    authenticate(username: "j.doe", password: "asd123") {
      token
    }
  }
"
@s3rgeym
Copy link
Author

s3rgeym commented Jun 16, 2019

function template(strings, ...keys) {
  return (function(...values) {
    var dict = values[values.length - 1] || {};
    var result = [strings[0]];
    keys.forEach(function(key, i) {
      var value = Number.isInteger(key) ? values[key] : dict[key];
      result.push(value, strings[i + 1]);
    });
    return result.join('');
  });
}

var t1Closure = template`${0}${1}${0}!`;
t1Closure('Y', 'A');  // "YAY!"
var t2Closure = template`${0} ${'foo'}!`;
t2Closure('Hello', {foo: 'World'});  // "Hello World!"

@s3rgeym
Copy link
Author

s3rgeym commented Jun 18, 2019

NPM

# Обновить пакет до последней версии
$ npm i vue@latest --save --force

# Обновить все пакеты
$ npm install -g npm-check-updates
$ ncu -u
$ npm i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment