Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
remove word boundary, #173 (#274)
Browse files Browse the repository at this point in the history
remove word boundary, #173
  • Loading branch information
GaurangTandon authored Jun 10, 2019
2 parents 2dbd4e9 + 858fe18 commit 3c0e04f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 53 deletions.
35 changes: 17 additions & 18 deletions js/primitiveExtend.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ import { getHTML, setHTML } from "./textmethods";
* This does not need to wait for page load.
*/
export function primitiveExtender() {
Date.MONTHS = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
Date.DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
Date.MILLISECONDS_IN_A_DAY = 86400 * 1000;
const MONTHS = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
],
DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
// eslint-disable-next-line no-proto
NodeList.prototype.__proto__ = Array.prototype;

Expand Down Expand Up @@ -130,13 +129,13 @@ export function primitiveExtender() {
};

Date.parseDay = function (dayNum, type) {
return type === "full" ? Date.DAYS[dayNum] : Date.DAYS[dayNum].slice(0, 3);
return type === "full" ? DAYS[dayNum] : DAYS[dayNum].slice(0, 3);
};

// accepts num (0-11); returns month
// type means full, or half
Date.parseMonth = function (month, type) {
return type === "full" ? Date.MONTHS[month] : Date.MONTHS[month].slice(0, 3);
return type === "full" ? MONTHS[month] : MONTHS[month].slice(0, 3);
};

// appends th, st, nd, to date
Expand Down
69 changes: 34 additions & 35 deletions js/snippetClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ function Snip(name, body, timestamp) {
let macro,
macroRegex,
macroRegexString,
elm,
macroFunc,
dateArithmeticChange,
date = new Date(),
Expand All @@ -456,7 +455,7 @@ function Snip(name, body, timestamp) {
if (/M/.test(macroRegexString)) {
timeChange
+= Date.getTotalDeviationFrom30DaysMonth(dateArithmeticMatch)
* Date.MILLISECONDS_IN_A_DAY;
* MILLISECONDS_IN_A_DAY;
}

timeChange += dateArithmeticChange * dateArithmeticMatch;
Expand All @@ -482,11 +481,9 @@ function Snip(name, body, timestamp) {

// operate on text (it is the one inside brackets of %d)
for (let i = 0, len = Snip.MACROS.length; i < len; i++) {
// macros has regex-function pairs
macro = Snip.MACROS[i];
[macroRegexString, elm] = macro;
[macroRegexString, [macroFunc, dateArithmeticChange]] = macro;
macroRegex = new RegExp(macroRegexString, "g");
[macroFunc, dateArithmeticChange] = elm;

userInputMacroText.replace(macroRegex, dateReplacer);
}
Expand Down Expand Up @@ -573,9 +570,11 @@ Snip.CARET_POSITION_STUFFED_REGEX = /\[\[%c\([v^<>\d]+\)\]\]/;
Snip.CARET_POSITION_SELECTION_START_REGEX = /\[\[%c\(s\)\]\]/;
Snip.CARET_POSITION_SELECTION_END_REGEX = /\[\[%c\(e\)\]\]/;
Snip.CARET_POSITION_SELECTION_END_STRING = "[[%c(e)]]";

const MILLISECONDS_IN_A_DAY = 86400 * 1000;
Snip.MACROS = [
[
"\\bs([+-]\\d+)?\\b",
"s([+-]\\d+)?",
[
function (date) {
return Number.padNumber(date.getSeconds());
Expand All @@ -584,7 +583,7 @@ Snip.MACROS = [
],
],
[
"\\bm([+-]\\d+)?\\b",
"m([+-]\\d+)?",
[
function (date) {
return Number.padNumber(date.getMinutes());
Expand All @@ -593,7 +592,7 @@ Snip.MACROS = [
],
],
[
"\\bhh([+-]\\d+)?\\b",
"hh([+-]\\d+)?",
[
function (date) {
return Number.padNumber(date.getHours());
Expand All @@ -602,7 +601,7 @@ Snip.MACROS = [
],
],
[
"\\bh([+-]\\d+)?\\b",
"h([+-]\\d+)?",
[
function (date) {
return Number.padNumber(Date.to12Hrs(date.getHours())[0]);
Expand All @@ -611,97 +610,97 @@ Snip.MACROS = [
],
],
[
"\\ba\\b",
"a",
[
function (date) {
return Date.to12Hrs(date.getHours())[1];
},
Date.MILLISECONDS_IN_A_DAY,
MILLISECONDS_IN_A_DAY,
],
],
[
"\\bDo([+-]\\d+)?\\b",
"Do([+-]\\d+)?",
[
function (date) {
return Date.formatDate(date.getDate());
},
Date.MILLISECONDS_IN_A_DAY,
MILLISECONDS_IN_A_DAY,
],
],
[
"\\bD([+-]\\d+)?\\b",
"D([+-]\\d+)?",
[
function (date) {
return Number.padNumber(date.getDate());
},
Date.MILLISECONDS_IN_A_DAY,
MILLISECONDS_IN_A_DAY,
],
],
[
"\\bdddd([+-]\\d+)?\\b",
"dddd([+-]\\d+)?",
[
function (date) {
return Date.parseDay(date.getDay(), "full");
},
Date.MILLISECONDS_IN_A_DAY,
MILLISECONDS_IN_A_DAY,
],
],
[
"\\bddd([+-]\\d+)?\\b",
"ddd([+-]\\d+)?",
[
function (date) {
return Date.parseDay(date.getDay(), "half");
},
Date.MILLISECONDS_IN_A_DAY,
MILLISECONDS_IN_A_DAY,
],
],
[
"\\bMMMM([+-]\\d+)?\\b",
"MMMM([+-]\\d+)?",
[
function (date) {
return Date.parseMonth(date.getMonth(), "full");
},
Date.MILLISECONDS_IN_A_DAY * 30,
MILLISECONDS_IN_A_DAY * 30,
],
],
[
"\\bMMM([+-]\\d+)?\\b",
"MMM([+-]\\d+)?",
[
function (date) {
return Date.parseMonth(date.getMonth(), "half");
},
Date.MILLISECONDS_IN_A_DAY * 30,
MILLISECONDS_IN_A_DAY * 30,
],
],
[
"\\bMM([+-]\\d+)?\\b",
"MM([+-]\\d+)?",
[
function (date) {
return Number.padNumber(date.getMonth() + 1);
},
Date.MILLISECONDS_IN_A_DAY * 30,
MILLISECONDS_IN_A_DAY * 30,
],
],
[
"\\bYYYY([+-]\\d+)?\\b",
"YYYY([+-]\\d+)?",
[
function (date) {
return date.getFullYear();
},
Date.MILLISECONDS_IN_A_DAY * 365,
MILLISECONDS_IN_A_DAY * 365,
],
],
[
"\\bYY([+-]\\d+)?\\b",
"YY([+-]\\d+)?",
[
function (date) {
return date.getFullYear() % 100;
},
Date.MILLISECONDS_IN_A_DAY * 365,
MILLISECONDS_IN_A_DAY * 365,
],
],
[
"\\bZZ\\b",
"ZZ",
[
function (date) {
return date.toString().match(/\((.*)\)/)[1];
Expand All @@ -710,7 +709,7 @@ Snip.MACROS = [
],
],
[
"\\bZ\\b",
"Z",
[
function (date) {
return date
Expand All @@ -723,7 +722,7 @@ Snip.MACROS = [
],
],
[
"\\bz\\b",
"z",
[
function (date) {
return date.toString().match(/GMT(.*?) /)[1];
Expand All @@ -732,16 +731,16 @@ Snip.MACROS = [
],
],
[
"\\bJ\\b",
"J",
[
function (date) {
return date.getDayOfYear();
},
0,
],
],
["\\bdate\\b", [Date.getFormattedDate, 0]],
["\\btime\\b", [Date.getCurrentTimestamp, 0]],
["date", [Date.getFormattedDate, 0]],
["time", [Date.getCurrentTimestamp, 0]],
];
Snip.fromObject = function (snip) {
const nSnip = new Snip(snip.name, snip.body);
Expand Down

0 comments on commit 3c0e04f

Please sign in to comment.