Skip to content

Instantly share code, notes, and snippets.

View AmyShackles's full-sized avatar
:octocat:

Amy Shackles AmyShackles

:octocat:
View GitHub Profile
@AmyShackles
AmyShackles / getUnicodeCodepoints.js
Last active January 12, 2024 00:34
Get Unicode codepoints associated with a particular property escape
const fs = require("fs");
const { unicode } = require("./Unicode");
const args = process.argv.slice(2);
const propertyEscape = args[0];
let ret = `const ${propertyEscape.toLowerCase()} = [`;
const regex = new RegExp(`\\p{${propertyEscape}}`, "gu");
for (let i = 0; i < unicode.length; i++) {
if (unicode[i].match(regex)) {
This file has been truncated, but you can view the full file.
const unicode=["\u0000","\u0001","\u0002","\u0003","\u0004","\u0005","\u0006","\u0007","\u0008","\u0009","\u000A","\u000B","\u000C","\u000D","\u000E","\u000F","\u0010","\u0011","\u0012","\u0013","\u0014","\u0015","\u0016","\u0017","\u0018","\u0019","\u001A","\u001B","\u001C","\u001D","\u001E","\u001F","\u0020","\u0021","\u0022","\u0023","\u0024","\u0025","\u0026","\u0027","\u0028","\u0029","\u002A","\u002B","\u002C","\u002D","\u002E","\u002F","\u0030","\u0031","\u0032","\u0033","\u0034","\u0035","\u0036","\u0037","\u0038","\u0039","\u003A","\u003B","\u003C","\u003D","\u003E","\u003F","\u0040","\u0041","\u0042","\u0043","\u0044","\u0045","\u0046","\u0047","\u0048","\u0049","\u004A","\u004B","\u004C","\u004D","\u004E","\u004F","\u0050","\u0051","\u0052","\u0053","\u0054","\u0055","\u0056","\u0057","\u0058","\u0059","\u005A","\u005B","\u005C","\u005D","\u005E","\u005F","\u0060","\u0061","\u0062","\u0063","\u0064","\u0065","\u0066","\u0067","\u0068","\u0069","\u006A","\u006B","\u006C","\u006D","\u006E","\u006F","
const desiredOutput = [
{
type: 'start_of_line',
startingIndex: 0,
lastIndex: 0,
group: '^',
children: [],
},
{
type: 'positive_lookbehind',
const inputArray = [
{
type: 'start_of_line',
startingIndex: 0,
lastIndex: 0,
group: '^'
},
{
type: 'positive_lookbehind',
group: '(?<=Hello (a(ga)in))',
@AmyShackles
AmyShackles / getRanges.js
Created November 19, 2020 07:10
Every Scripts option instantiated as a variable of the same name containing every code point matched by that script
/* Helper functions to generate the code points in a given script, expanding all of the values in a range */
function getRange([start, stop]) {
start = parseInt(start, 16);
stop = parseInt(stop, 16);
const codepoints = [];
for (start; start <= stop; start++) {
codepoints.push(start.toString(16).padStart(4, '0').toUpperCase())
}
return codepoints;
@AmyShackles
AmyShackles / script-extensions-unicode.md
Last active November 23, 2020 02:43
Codepoints matched by script_extension

Adlm: [\u0640]

Arab: [ \u060C, \u061B, \u061C, \u061F, \u0640, \u064B, \u064C,

Alias Canonical property name Matches letters and written signs belonging to _____ script
\p{Script=Adlm} \p{Script=Adlam} Adlam
\p{Script=Ahom} \p{Script=Ahom} Ahom
\p{Script=Hluw} \p{Script=Anatolian_Hieroglyphs} Anatolian Hieroglyphs
\p{Script=Arab} \p{Script=Arabic} Arabic
\p{Script=Armn} \p{Script=Armenian} Armenian
\p{Script=Avst} \p{Script=Avestan} Avestan
\p{Script=Bali} \p{Script=Balinese} Balinese
\p{Script=Bamu} \p{Script=Bamum} Bamum
@AmyShackles
AmyShackles / date.md
Last active March 4, 2021 21:48
Reference for dealing with JS Date objects

const date = new Date('08-14-1989 13:21:45')

GETTERS

Get time (since Unix Epoch)

const birthday = new Date('1989-08-14');
birthday.getTime() // 619056000000

Get timezone offset (current locale/system settings vs. UTC)

@AmyShackles
AmyShackles / alphanumericSort.js
Last active December 22, 2020 23:24
Natural/alphanumeric sort in JavaScript
let arr = ['1st', '2nd', '11th', '12th', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '13th'];
const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
arr.sort(collator.compare); // ["1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th"]
// If working with objects:
let planes = [{Model: "AT301A", Make: "Air Tractor"}, {Model: "KR-2", Make: "Starke"}, {Model: "V", Make: "Culver"}, {Model: "J-35", Make: "Beech"}];
planes.sort((a, b) => collator.compare(a.Make, b.Make)); // [{"Model":"AT301A","Make":"Air Tractor"},{"Model":"J-35","Make":"Beech"},{"Model":"V","Make":"Culver"},{"Model":"KR-2","Make":"Starke"}]
@AmyShackles
AmyShackles / regexes.js
Created October 16, 2020 05:42
Regular Expression Regular Expressions
const NAME = "(?<name>.+?)";
const NON_CAPTURE = "^(?<non_capture_group>\\(\\?:(?<non_capture>.+?)\\))$";
const NAMED_CAPTURE = "^(?<named_capture_group>\\(\\?<" + NAME + ">(?<named_capture>.+?)\\))$";
const CAPTURE = "^(?<capture_group>\\((?<capture>[^\\?:].*)\\))$";
const UNICODE_REGEX_IN_UNICODE_MODE = /(?<unicode>\\u{?(?<hex>[\da-fA-F]{4,5})\}?)/g;
const UNICODE_REGEX_NOT_IN_UNICODE_MODE = /(?<unicode>\\u(?<hex>[\da-fA-F]{4}))/g;
const DIGIT = "(?<digit>\\\\d)";
const NON_DIGIT = "(?<non_digit>\\\\D)";
const ALPHANUMERIC = "(?<alphanumeric>\\\\w)";
const NON_ALPHANUMERIC = "(?<non_alphanumeric>\\\\W)";