Skip to content

Commit c39c14b

Browse files
authored
Merge pull request #4 from mat2ja/release/v0.5
Release/v0.5
2 parents 0fb49e8 + 3fcd0be commit c39c14b

14 files changed

+352
-67
lines changed

README.md

+217-34
Large diffs are not rendered by default.

src/docs-gen/snippets.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ type SnippetRow = {
1818
body: string | string[];
1919
};
2020

21+
const truncateOptions = (str: string) => {
22+
const regex = /\|([^|]+)\|/g;
23+
return str.replace(regex, (_match, p1) => {
24+
const [first] = p1.split(",").map((o: string) => o.trim());
25+
return `|${first},...|`;
26+
});
27+
};
28+
2129
const snippetRow = ({ prefix, name, body }: SnippetRow) => {
2230
const cols = joinByNewLine([
2331
$colCode(prefix),
2432
$col(name),
25-
$colCodeBlock(parseMultiline(body)),
33+
$colCodeBlock(truncateOptions(parseMultiline(body))),
2634
]);
2735

2836
return $row(cols);

src/snippets/js/app.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { arrayMethods } from "./array-methods.ts";
2+
import { assignments } from "./assignments.ts";
23
import { classes } from "./classes.ts";
34
import { console } from "./console.ts";
45
import { dates } from "./dates.ts";
5-
import { assignments } from "./assignments.ts";
66
import { dom } from "./dom.ts";
77
import { flowControl } from "./flow-control.ts";
88
import { functions } from "./functions.ts";
99
import { json } from "./json.ts";
1010
import { loops } from "./loops.ts";
1111
import { misc } from "./misc.ts";
1212
import { modules } from "./modules.ts";
13+
import { node } from "./node.ts";
1314
import { objects } from "./objects.ts";
1415
import { operatorsExpressionsLiterals } from "./operators-expressions-literals.ts";
1516
import { promises } from "./promises.ts";
@@ -18,6 +19,7 @@ import { testing } from "./testing.ts";
1819
import { timers } from "./timers.ts";
1920
import { types } from "./types.ts";
2021
import { uncategorized } from "./uncategorized.ts";
22+
import { intl } from "./intl.ts";
2123

2224
export const javascript = [
2325
assignments,
@@ -36,8 +38,10 @@ export const javascript = [
3638
json,
3739
dom,
3840
dates,
41+
node,
3942
testing,
4043
types,
4144
misc,
45+
intl,
4246
uncategorized,
4347
];

src/snippets/js/array-methods.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const arrayMethods: XSnippetDefinition = {
1717
name: "Array.reduce()",
1818
body: "$1.reduce((${2:acc}, ${3:curr}) => {\n\t$0\n}, ${4:initial})",
1919
},
20-
"reduce-right": {
20+
reduceRight: {
2121
name: "Array.reduceRight()",
2222
body: "$1.reduceRight((${2:acc}, ${3:curr}) => {\n\t$0\n}, ${4:initial})",
2323
},
@@ -41,15 +41,15 @@ export const arrayMethods: XSnippetDefinition = {
4141
name: "Array.reverse()",
4242
body: "$1.reverse()",
4343
},
44-
"map-string": {
44+
mapStr: {
4545
name: "Array.map() as string",
4646
body: "$1.map(String)",
4747
},
48-
"map-number": {
48+
mapNum: {
4949
name: "Array.map() as number",
5050
body: "$1.map(Number)",
5151
},
52-
"filter-true": {
52+
filterTrue: {
5353
name: "Array.filter() truthy",
5454
body: "$1.filter(Boolean)",
5555
},

src/snippets/js/assignments.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const assignments: XSnippetDefinition = {
2525
name: "const string assignment",
2626
body: "const $1 = '$2';",
2727
},
28+
las: {
29+
name: "let string assignment",
30+
body: "let $1 = '$2';",
31+
},
2832
car: {
2933
name: "const array assignment",
3034
body: "const $1 = [$0]",
@@ -35,11 +39,11 @@ export const assignments: XSnippetDefinition = {
3539
},
3640
dob: {
3741
name: "object destructuring",
38-
body: "const { $0 } = ${1:object}",
42+
body: "const { $0 } = ${1:object};",
3943
},
4044
dar: {
4145
name: "array destructuring",
42-
body: "const [$0] = ${1:array}",
46+
body: "const [$0] = ${1:array};",
4347
},
4448
},
4549
};

src/snippets/js/classes.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const classes: XSnippetDefinition = {
3333
"}",
3434
],
3535
},
36-
ctor: {
36+
cst: {
3737
name: "class constructor",
38-
body: "constructor($1) {$0}",
38+
body: "constructor($1) {\n\t$0\n}",
3939
},
4040
get: {
4141
name: "getter",
@@ -48,7 +48,7 @@ export const classes: XSnippetDefinition = {
4848
gs: {
4949
name: "getter and setter",
5050
body:
51-
"get ${1:property}() {\n\t$0\n}\nset ${1:property}(${2:value}) {\n\t\n}",
51+
"get ${1:property}() {\n\t$0\n}\nset ${1:property}(${2:value}) {\n\t$0\n}",
5252
},
5353
met: {
5454
name: "method",

src/snippets/js/console.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ export const console = {
5353
},
5454
cll: {
5555
name: "console.log (labeled)",
56-
body: "console.log('$1 ->', $1$2)",
56+
body: "console.log('$1 :', $1$2)",
5757
},
5858
cel: {
5959
name: "console.error (labeled)",
60-
body: "console.error('$1 ->', $1$2)",
60+
body: "console.error('$1 :', $1$2)",
6161
},
6262
cwl: {
6363
name: "console.warn (labeled)",
64-
body: "console.warn('$1 ->', ${2:$1})",
64+
body: "console.warn('$1 :', ${2:$1})",
6565
},
6666
},
6767
};

src/snippets/js/flow-control.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const flowControl: XSnippetDefinition = {
1919
},
2020
el: {
2121
name: "else statement",
22-
body: "else {\n\t$3\n}",
22+
body: "else {\n\t$0\n}",
2323
},
2424
ei: {
2525
name: "else if statement",

src/snippets/js/intl.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export const intl = {
2+
meta: {
3+
title: "Intl",
4+
description: "Internationalization API",
5+
},
6+
snippets: {
7+
inf: {
8+
name: "Intl.NumberFormat",
9+
body:
10+
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}'$3).format($2);",
11+
},
12+
infs: {
13+
name: "Intl.NumberFormat style",
14+
body: [
15+
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
16+
"\tstyle: '${3|decimal,currency,percent,unit|}',$4",
17+
"}).format($2);",
18+
],
19+
},
20+
infc: {
21+
name: "Intl.NumberFormat as currency",
22+
body: [
23+
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
24+
"\tstyle: 'currency',",
25+
"\tcurrency: '${3|USD,EUR,GBP,AUD,CAD,JPY|}',$4",
26+
"}).format($2);",
27+
],
28+
},
29+
infp: {
30+
name: "Intl.NumberFormat as percentage",
31+
body: [
32+
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
33+
"\tstyle: 'percent',$3",
34+
"}).format($2);",
35+
],
36+
},
37+
infu: {
38+
name: "Intl.NumberFormat as unit",
39+
body: [
40+
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
41+
"\tstyle: 'unit',",
42+
"\tunit: '${3|acceleration-g-force,acceleration-meter-per-square-second,angle-arc-minute,angle-arc-second,angle-degree,angle-radian,angle-revolution,area-acre,area-hectare,area-square-centimeter,area-square-foot,area-square-inch,area-square-kilometer,area-square-meter,area-square-mile,area-square-yard,area-dunam,concentr-karat,concentr-milligram-ofglucose-per-deciliter,concentr-millimole-per-liter,concentr-percent,concentr-permille,concentr-permyriad,concentr-permillion,concentr-mole,concentr-item,concentr-portion,concentr-ofglucose,consumption-liter-per-100-kilometer,consumption-liter-per-kilometer,consumption-mile-per-gallon,consumption-mile-per-gallon-imperial,digital-bit,digital-byte,digital-gigabit,digital-gigabyte,digital-kilobit,digital-kilobyte,digital-megabit,digital-megabyte,digital-petabyte,digital-terabit,digital-terabyte,duration-century,duration-decade,duration-day,duration-day-person,duration-hour,duration-microsecond,duration-millisecond,duration-minute,duration-month,duration-month-person,duration-nanosecond,duration-quarter,duration-second,duration-week,duration-week-person,duration-year,duration-year-person,electric-ampere,electric-milliampere,electric-ohm,electric-volt,energy-calorie,energy-foodcalorie,energy-joule,energy-kilocalorie,energy-kilojoule,energy-kilowatt-hour,energy-electronvolt,energy-therm-us,energy-british-thermal-unit,force-pound-force,force-newton,force-kilowatt-hour-per-100-kilometer,frequency-gigahertz,frequency-hertz,frequency-kilohertz,frequency-megahertz,graphics-dot,graphics-dot-per-centimeter,graphics-dot-per-inch,graphics-em,graphics-megapixel,graphics-pixel,graphics-pixel-per-centimeter,graphics-pixel-per-inch,length-100-kilometer,length-astronomical-unit,length-centimeter,length-decimeter,length-fathom,length-foot,length-furlong,length-inch,length-kilometer,length-light-year,length-meter,length-micrometer,length-mile,length-mile-scandinavian,length-millimeter,length-nanometer,length-nautical-mile,length-parsec,length-picometer,length-point,length-yard,length-earth-radius,length-solar-radius,light-candela,light-lumen,light-lux,light-solar-luminosity,mass-carat,mass-grain,mass-gram,mass-kilogram,mass-tonne,mass-microgram,mass-milligram,mass-ounce,mass-ounce-troy,mass-pound,mass-stone,mass-ton,mass-dalton,mass-earth-mass,mass-solar-mass,power-gigawatt,power-horsepower,power-kilowatt,power-megawatt,power-milliwatt,power-watt,pressure-atmosphere,pressure-hectopascal,pressure-inch-ofhg,pressure-bar,pressure-millibar,pressure-millimeter-ofhg,pressure-pound-force-per-square-inch,pressure-pascal,pressure-kilopascal,pressure-megapascal,pressure-ofhg,speed-kilometer-per-hour,speed-knot,speed-meter-per-second,speed-mile-per-hour,temperature-celsius,temperature-fahrenheit,temperature-generic,temperature-kelvin,torque-pound-force-foot,torque-newton-meter,volume-acre-foot,volume-bushel,volume-centiliter,volume-cubic-centimeter,volume-cubic-foot,volume-cubic-inch,volume-cubic-kilometer,volume-cubic-meter,volume-cubic-mile,volume-cubic-yard,volume-cup,volume-cup-metric,volume-deciliter,volume-dessert-spoon,volume-dessert-spoon-imperial,volume-drop,volume-dram,volume-jigger,volume-pinch,volume-quart-imperial,volume-fluid-ounce,volume-fluid-ounce-imperial,volume-gallon,volume-gallon-imperial,volume-hectoliter,volume-liter,volume-megaliter,volume-milliliter,volume-pint,volume-pint-metric,volume-quart,volume-tablespoon,volume-teaspoon,volume-barrel|}',",
43+
"\tunitDisplay: '${4|long,short,narrow|}',$0",
44+
"}).format($2);",
45+
],
46+
},
47+
idtf: {
48+
name: "Intl.DateTimeFormat",
49+
body:
50+
"new Intl.DateTimeFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}'$3).format($2);",
51+
},
52+
idtfs: {
53+
name: "Intl.DateTimeFormat with options",
54+
body: [
55+
"new Intl.DateTimeFormat ('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
56+
"\tdateStyle: '$3',$0",
57+
"}).format($2);",
58+
],
59+
},
60+
},
61+
};

src/snippets/js/json.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export const json: XSnippetDefinition = {
1313
name: "JSON stringify",
1414
body: "JSON.stringify(${1:value})",
1515
},
16-
jsp: {
17-
name: "JSON stringify (pretty)",
16+
jsf: {
17+
name: "JSON stringify (formatted)",
1818
body: "JSON.stringify(${1:value}, null, 2)",
1919
},
2020
jss: {
2121
name: "JSON.stringify if not string",
22-
body: "typeof ${1:value} === 'string' ? value : JSON.stringify($1)",
22+
body: "typeof $1 === 'string' ? $1 : JSON.stringify($1)",
2323
},
2424
},
2525
};

src/snippets/js/loops.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export const loops: XSnippetDefinition = {
88
fl: {
99
name: "for loop",
1010
body:
11-
"for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length; ${1:i} < ${2:len}; ${1:i}++) {\n\t$0\n}",
11+
"for (let ${1:i} = 0, ${2:len} = ${3:iter}.length; ${1:i} < ${2:len}; ${1:i}++) {\n\t$0\n}",
1212
},
1313
rfl: {
1414
name: "reverse for loop",
1515
body:
16-
"for (let ${1:i} = ${2:iterable}.length - 1; ${1:i} >= 0; ${1:i}--) {\n\t$0\n}",
16+
"for (let ${1:i} = ${2:iter}.length - 1; ${1:i} >= 0; ${1:i}--) {\n\t$0\n}",
1717
},
1818
flr: {
1919
name: "for loop (range)",
@@ -35,5 +35,9 @@ export const loops: XSnippetDefinition = {
3535
name: "while loop",
3636
body: "while (${1:true}) {\n\t$0\n}",
3737
},
38+
dwl: {
39+
name: "do while loop",
40+
body: "do {\n\t$0\n} while ($1)",
41+
},
3842
},
3943
};

src/snippets/js/node.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { XSnippetDefinition } from "../../models/app.ts";
2+
3+
export const node: XSnippetDefinition = {
4+
meta: {
5+
title: "Node",
6+
},
7+
snippets: {
8+
re: {
9+
name: "require",
10+
body: "require('${1:module}')",
11+
},
12+
req: {
13+
name: "require assignment",
14+
body: "const ${1} = require('${1:module}');",
15+
},
16+
},
17+
};

src/snippets/js/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const types: XSnippetDefinition = {
1212
tof: {
1313
name: "typeof",
1414
body:
15-
"typeof ${1:value} === '${2|bigint,boolean,function,number,object,symbol,undefined|}'",
15+
"typeof ${1:value} === '${2|undefined,string,number,object,function,boolean,symbol,bigint|}'",
1616
},
1717
iof: {
1818
name: "instanceof",

src/snippets/js/uncategorized.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ export const uncategorized: XSnippetDefinition = {
66
description: "Will be sorted into appropriate categories in the future.",
77
},
88
snippets: {
9+
aat: {
10+
name: "array.at",
11+
body: "$1.at(${2:0})",
12+
},
13+
am: {
14+
name: "array merge",
15+
body: "[...$1]",
16+
},
17+
om: {
18+
name: "object merge",
19+
body: "{ ...$1 }",
20+
},
921
uniq: {
1022
name: "array of unique values",
1123
body: "[...new Set($0)]",
@@ -18,21 +30,13 @@ export const uncategorized: XSnippetDefinition = {
1830
name: "parse float",
1931
body: "parseFloat($1)",
2032
},
21-
am: {
22-
name: "array merge",
23-
body: "[...$1]",
24-
},
25-
om: {
26-
name: "object merge",
27-
body: "{ ...$1 }",
28-
},
29-
aat: {
30-
name: "array.at",
31-
body: "$1.at(${2:0})",
32-
},
3333
seq: {
3434
name: "sequence of 0..n",
3535
body: "[...Array(${1:length}).keys()]",
3636
},
37+
te: {
38+
name: "throw error",
39+
body: ["throw new ${1|Error,TypeError,RangeError|}($0);"],
40+
},
3741
},
3842
};

0 commit comments

Comments
 (0)