Skip to content

Instantly share code, notes, and snippets.

View shisama's full-sized avatar

Masashi Hirano shisama

View GitHub Profile
@shisama
shisama / no-f-word.js
Last active October 4, 2019 13:43
My first eslint rule 'no-f-word'. This rule prohibits literal including F word.
module.exports = context => {
return {
Literal: (node) => {
if(node.value.match(/fuck/)) {
context.report({
node,
message: 'Don\'t use the F word!'
})
}
}
#!/usr/bin/env node
const path = require('path')
const execa = require('execa');
const problemPackage = 'cowsay';
const {devDependencies, dependencies} = require(path.resolve(__dirname, 'package.json'));
const problemPackageVersion = {...devDependencies, ...dependencies}[problemPackage]
@shisama
shisama / not_sorted_nullable_properties_interface.ts
Last active July 7, 2020 15:26
Object Performance Test with TypeScript Playground & V8 7.7
const start = performance.now();
interface Member {
name: string;
birthday: Date | null;
url: string | null;
instrument: string | null;
}
const john: Member = {
name: 'John Lennon',
<!doctype html>
<html>
<head>
</head>
<body>
<div id="info"></div>
<script>
const markerNameA = "example-marker-a"
const markerNameB = "example-marker-b"
@shisama
shisama / extract_exclude_sample1.ts
Last active June 9, 2019 05:34
Advanced built-in types you may have never used
type SupportedDomains = "google.com" | "amazon.com" | "google.co.jp" | "amazon.co.jp"
type USDomains = "google.com" | "amazon.com" | "facebook.com"
// "google.com" | "amazon.com"
type SupportedUSDomains = Extract<SupportedDomains, USDomains>
// "google.co.jp" | "amazon.co.jp"
type UnsupportedUSDomains = Exclude<SupportedDomains, USDomains>
const domain1: SupportedDomains = "google.co.jp"
@shisama
shisama / symbol_description.js
Created April 23, 2019 18:47
Symbol#description - New JavaScript Features in Node.js v12
console.log(Symbol('desc').description);
// expected output: "desc"
console.log(Symbol.iterator.description);
// expected output: "Symbol.iterator"
@shisama
shisama / string_matchall.js
Last active April 24, 2019 01:00
String#matchAll - New JavaScript Features in Node.js v12
const regexp = /t(e)(st(\d?))/g;
const str = 'test1test2';
const array = [...str.matchAll(regexp)];
console.log(array[0])
// ['test1', 'e', 'st1', '1', index: 0, input: 'test1test2', groups: undefined]
console.log(array[1])
// ['test2', 'e', 'st2', '2', index: 5, input: 'test1test2', groups: undefined]
@shisama
shisama / object_fromEntries.js
Last active April 23, 2019 20:00
Object.fromEntries - New JavaScript Features in Node.js v12
const entries = new Map([
['foo', 'bar'],
['baz', 42]
]);
const obj = Object.fromEntries(entries);
console.log(obj);
// expected output: Object { foo: "bar", baz: 42 }
@shisama
shisama / Intl_RelativeTimeFormat.js
Last active April 23, 2019 18:23
Intl.RelativeTimeFormat - New JavaScript Features in Node.js v12
var rtf1 = new Intl.RelativeTimeFormat('en', { style: 'narrow' });
console.log(rtf1.format(3, 'quarter'));
//expected output: "in 3 qtrs."
console.log(rtf1.format(-1, 'day'));
//expected output: "1 day ago"
var rtf2 = new Intl.RelativeTimeFormat('ja', { numeric: 'auto' });
@shisama
shisama / Intl_Locale.js
Created April 23, 2019 17:43
Intl.Locale - New JavaScript Features in Node.js v12
let loc = new Intl.Locale("pl-u-hc-h12", {
calendar: 'gregory'
});
console.log(loc.language); // "pl"
console.log(loc.hourCycle); // "h12"
console.log(loc.calendar); // "gregory"
console.log(loc.toString()); // "pl-u-ca-gregory-hc-h12"