Skip to content

Release/v0.5 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 217 additions & 34 deletions README.md

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/docs-gen/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ type SnippetRow = {
body: string | string[];
};

const truncateOptions = (str: string) => {
const regex = /\|([^|]+)\|/g;
return str.replace(regex, (_match, p1) => {
const [first] = p1.split(",").map((o: string) => o.trim());
return `|${first},...|`;
});
};

const snippetRow = ({ prefix, name, body }: SnippetRow) => {
const cols = joinByNewLine([
$colCode(prefix),
$col(name),
$colCodeBlock(parseMultiline(body)),
$colCodeBlock(truncateOptions(parseMultiline(body))),
]);

return $row(cols);
Expand Down
6 changes: 5 additions & 1 deletion src/snippets/js/app.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { arrayMethods } from "./array-methods.ts";
import { assignments } from "./assignments.ts";
import { classes } from "./classes.ts";
import { console } from "./console.ts";
import { dates } from "./dates.ts";
import { assignments } from "./assignments.ts";
import { dom } from "./dom.ts";
import { flowControl } from "./flow-control.ts";
import { functions } from "./functions.ts";
import { json } from "./json.ts";
import { loops } from "./loops.ts";
import { misc } from "./misc.ts";
import { modules } from "./modules.ts";
import { node } from "./node.ts";
import { objects } from "./objects.ts";
import { operatorsExpressionsLiterals } from "./operators-expressions-literals.ts";
import { promises } from "./promises.ts";
Expand All @@ -18,6 +19,7 @@ import { testing } from "./testing.ts";
import { timers } from "./timers.ts";
import { types } from "./types.ts";
import { uncategorized } from "./uncategorized.ts";
import { intl } from "./intl.ts";

export const javascript = [
assignments,
Expand All @@ -36,8 +38,10 @@ export const javascript = [
json,
dom,
dates,
node,
testing,
types,
misc,
intl,
uncategorized,
];
8 changes: 4 additions & 4 deletions src/snippets/js/array-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const arrayMethods: XSnippetDefinition = {
name: "Array.reduce()",
body: "$1.reduce((${2:acc}, ${3:curr}) => {\n\t$0\n}, ${4:initial})",
},
"reduce-right": {
reduceRight: {
name: "Array.reduceRight()",
body: "$1.reduceRight((${2:acc}, ${3:curr}) => {\n\t$0\n}, ${4:initial})",
},
Expand All @@ -41,15 +41,15 @@ export const arrayMethods: XSnippetDefinition = {
name: "Array.reverse()",
body: "$1.reverse()",
},
"map-string": {
mapStr: {
name: "Array.map() as string",
body: "$1.map(String)",
},
"map-number": {
mapNum: {
name: "Array.map() as number",
body: "$1.map(Number)",
},
"filter-true": {
filterTrue: {
name: "Array.filter() truthy",
body: "$1.filter(Boolean)",
},
Expand Down
8 changes: 6 additions & 2 deletions src/snippets/js/assignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const assignments: XSnippetDefinition = {
name: "const string assignment",
body: "const $1 = '$2';",
},
las: {
name: "let string assignment",
body: "let $1 = '$2';",
},
car: {
name: "const array assignment",
body: "const $1 = [$0]",
Expand All @@ -35,11 +39,11 @@ export const assignments: XSnippetDefinition = {
},
dob: {
name: "object destructuring",
body: "const { $0 } = ${1:object}",
body: "const { $0 } = ${1:object};",
},
dar: {
name: "array destructuring",
body: "const [$0] = ${1:array}",
body: "const [$0] = ${1:array};",
},
},
};
6 changes: 3 additions & 3 deletions src/snippets/js/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export const classes: XSnippetDefinition = {
"}",
],
},
ctor: {
cst: {
name: "class constructor",
body: "constructor($1) {$0}",
body: "constructor($1) {\n\t$0\n}",
},
get: {
name: "getter",
Expand All @@ -48,7 +48,7 @@ export const classes: XSnippetDefinition = {
gs: {
name: "getter and setter",
body:
"get ${1:property}() {\n\t$0\n}\nset ${1:property}(${2:value}) {\n\t\n}",
"get ${1:property}() {\n\t$0\n}\nset ${1:property}(${2:value}) {\n\t$0\n}",
},
met: {
name: "method",
Expand Down
6 changes: 3 additions & 3 deletions src/snippets/js/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export const console = {
},
cll: {
name: "console.log (labeled)",
body: "console.log('$1 ->', $1$2)",
body: "console.log('$1 :', $1$2)",
},
cel: {
name: "console.error (labeled)",
body: "console.error('$1 ->', $1$2)",
body: "console.error('$1 :', $1$2)",
},
cwl: {
name: "console.warn (labeled)",
body: "console.warn('$1 ->', ${2:$1})",
body: "console.warn('$1 :', ${2:$1})",
},
},
};
2 changes: 1 addition & 1 deletion src/snippets/js/flow-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const flowControl: XSnippetDefinition = {
},
el: {
name: "else statement",
body: "else {\n\t$3\n}",
body: "else {\n\t$0\n}",
},
ei: {
name: "else if statement",
Expand Down
61 changes: 61 additions & 0 deletions src/snippets/js/intl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export const intl = {
meta: {
title: "Intl",
description: "Internationalization API",
},
snippets: {
inf: {
name: "Intl.NumberFormat",
body:
"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);",
},
infs: {
name: "Intl.NumberFormat style",
body: [
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
"\tstyle: '${3|decimal,currency,percent,unit|}',$4",
"}).format($2);",
],
},
infc: {
name: "Intl.NumberFormat as currency",
body: [
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
"\tstyle: 'currency',",
"\tcurrency: '${3|USD,EUR,GBP,AUD,CAD,JPY|}',$4",
"}).format($2);",
],
},
infp: {
name: "Intl.NumberFormat as percentage",
body: [
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
"\tstyle: 'percent',$3",
"}).format($2);",
],
},
infu: {
name: "Intl.NumberFormat as unit",
body: [
"new Intl.NumberFormat('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
"\tstyle: 'unit',",
"\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|}',",
"\tunitDisplay: '${4|long,short,narrow|}',$0",
"}).format($2);",
],
},
idtf: {
name: "Intl.DateTimeFormat",
body:
"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);",
},
idtfs: {
name: "Intl.DateTimeFormat with options",
body: [
"new Intl.DateTimeFormat ('${1|en-US,en-GB,en-CA,de-DE,fr-FR,es-ES,zh-CN,ru-RU,ja-JP|}', {",
"\tdateStyle: '$3',$0",
"}).format($2);",
],
},
},
};
6 changes: 3 additions & 3 deletions src/snippets/js/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const json: XSnippetDefinition = {
name: "JSON stringify",
body: "JSON.stringify(${1:value})",
},
jsp: {
name: "JSON stringify (pretty)",
jsf: {
name: "JSON stringify (formatted)",
body: "JSON.stringify(${1:value}, null, 2)",
},
jss: {
name: "JSON.stringify if not string",
body: "typeof ${1:value} === 'string' ? value : JSON.stringify($1)",
body: "typeof $1 === 'string' ? $1 : JSON.stringify($1)",
},
},
};
8 changes: 6 additions & 2 deletions src/snippets/js/loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const loops: XSnippetDefinition = {
fl: {
name: "for loop",
body:
"for (let ${1:i} = 0, ${2:len} = ${3:iterable}.length; ${1:i} < ${2:len}; ${1:i}++) {\n\t$0\n}",
"for (let ${1:i} = 0, ${2:len} = ${3:iter}.length; ${1:i} < ${2:len}; ${1:i}++) {\n\t$0\n}",
},
rfl: {
name: "reverse for loop",
body:
"for (let ${1:i} = ${2:iterable}.length - 1; ${1:i} >= 0; ${1:i}--) {\n\t$0\n}",
"for (let ${1:i} = ${2:iter}.length - 1; ${1:i} >= 0; ${1:i}--) {\n\t$0\n}",
},
flr: {
name: "for loop (range)",
Expand All @@ -35,5 +35,9 @@ export const loops: XSnippetDefinition = {
name: "while loop",
body: "while (${1:true}) {\n\t$0\n}",
},
dwl: {
name: "do while loop",
body: "do {\n\t$0\n} while ($1)",
},
},
};
17 changes: 17 additions & 0 deletions src/snippets/js/node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { XSnippetDefinition } from "../../models/app.ts";

export const node: XSnippetDefinition = {
meta: {
title: "Node",
},
snippets: {
re: {
name: "require",
body: "require('${1:module}')",
},
req: {
name: "require assignment",
body: "const ${1} = require('${1:module}');",
},
},
};
2 changes: 1 addition & 1 deletion src/snippets/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const types: XSnippetDefinition = {
tof: {
name: "typeof",
body:
"typeof ${1:value} === '${2|bigint,boolean,function,number,object,symbol,undefined|}'",
"typeof ${1:value} === '${2|undefined,string,number,object,function,boolean,symbol,bigint|}'",
},
iof: {
name: "instanceof",
Expand Down
28 changes: 16 additions & 12 deletions src/snippets/js/uncategorized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ export const uncategorized: XSnippetDefinition = {
description: "Will be sorted into appropriate categories in the future.",
},
snippets: {
aat: {
name: "array.at",
body: "$1.at(${2:0})",
},
am: {
name: "array merge",
body: "[...$1]",
},
om: {
name: "object merge",
body: "{ ...$1 }",
},
uniq: {
name: "array of unique values",
body: "[...new Set($0)]",
Expand All @@ -18,21 +30,13 @@ export const uncategorized: XSnippetDefinition = {
name: "parse float",
body: "parseFloat($1)",
},
am: {
name: "array merge",
body: "[...$1]",
},
om: {
name: "object merge",
body: "{ ...$1 }",
},
aat: {
name: "array.at",
body: "$1.at(${2:0})",
},
seq: {
name: "sequence of 0..n",
body: "[...Array(${1:length}).keys()]",
},
te: {
name: "throw error",
body: ["throw new ${1|Error,TypeError,RangeError|}($0);"],
},
},
};