-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ buildMeasuresParser | |
} | ||
} | ||
|
||
// The main measure parser. All measures should extend from this. | ||
abstractMeasureParser | ||
atoms measureNameAtom | ||
description Base parser all measures extend. | ||
cueFromId | ||
boolean isMeasure true | ||
float sortIndex 1.9 | ||
|
@@ -49,16 +49,34 @@ abstractMeasureParser | |
|
||
// String Measures | ||
abstractAtomMeasureParser | ||
description A measure that contains a single atom. | ||
description Contains a single word. | ||
atoms measureNameAtom atomAtom | ||
example | ||
nicknameParser | ||
extends abstractAtomMeasureParser | ||
id Breck | ||
nickname breck | ||
extends abstractMeasureParser | ||
|
||
abstractStringMeasureParser | ||
description General text data with no specific format. | ||
catchAllAtomType stringAtom | ||
example | ||
titleParser | ||
extends abstractStringMeasureParser | ||
id Breck | ||
title I build languages for scientists of all ages | ||
extends abstractMeasureParser | ||
|
||
abstractTextareaMeasureParser | ||
string typeForWebForms textarea | ||
example | ||
bioParser | ||
extends abstractTextareaMeasureParser | ||
id Breck | ||
bio | ||
I build languages for scientists of all ages | ||
description Long-form text content with preserved line breaks. | ||
extends abstractMeasureParser | ||
baseParser blobParser | ||
javascript | ||
|
@@ -67,21 +85,38 @@ abstractTextareaMeasureParser | |
} | ||
|
||
abstractEmailMeasureParser | ||
description Email address. | ||
example | ||
emailParser | ||
extends abstractEmailMeasureParser | ||
id Breck | ||
email [email protected] | ||
string typeForWebForms email | ||
atoms measureNameAtom emailAddressAtom | ||
extends abstractAtomMeasureParser | ||
|
||
// URL Parsers | ||
abstractUrlMeasureParser | ||
description A single url. | ||
example | ||
homepageParser | ||
extends abstractUrlMeasureParser | ||
id Breck | ||
homepage https://breckyunits.com | ||
string typeForWebForms url | ||
atoms measureNameAtom urlAtom | ||
extends abstractAtomMeasureParser | ||
|
||
|
||
// Required ID measure which denotes a concept | ||
abstractIdParser | ||
cue id | ||
description What is the ID of this concept? | ||
extends abstractStringMeasureParser | ||
example | ||
idParser | ||
extends abstractIdParser | ||
id breck | ||
float sortIndex 1 | ||
boolean isMeasureRequired true | ||
boolean isConceptDelimiter true | ||
|
@@ -101,44 +136,135 @@ abstractIdParser | |
return errors | ||
} | ||
|
||
abstractIdMeasureParser | ||
description Alias for abstractIdParser. | ||
extends abstractIdParser | ||
|
||
// Numeric Measures | ||
abstractNumericMeasureParser | ||
string typeForWebForms number | ||
description Base number type. | ||
extends abstractMeasureParser | ||
javascript | ||
get measureValue() { | ||
const {content} = this | ||
return content === undefined ? "" : parseFloat(content) | ||
} | ||
abstractNumberMeasureParser | ||
description Alias to abstractNumericMeasureParser. | ||
extends abstractNumericMeasureParser | ||
|
||
abstractIntegerMeasureParser | ||
description An integer. | ||
example | ||
ageParser | ||
extends abstractIntegerMeasureParser | ||
id Breck | ||
age 40 | ||
atoms measureNameAtom integerAtom | ||
extends abstractNumericMeasureParser | ||
javascript | ||
get measureValue() { | ||
const {content} = this | ||
return content === undefined ? "" : parseInt(content) | ||
} | ||
abstractIntMeasureParser | ||
description Alias to abstractIntegerMeasureParser. | ||
extends abstractIntegerMeasureParser | ||
|
||
abstractFloatMeasureParser | ||
description A float. | ||
example | ||
temperatureParser | ||
extends abstractFloatMeasureParser | ||
id Breck | ||
temperature 31.8 | ||
atoms measureNameAtom floatAtom | ||
extends abstractNumericMeasureParser | ||
|
||
abstractPercentageMeasureParser | ||
description A percentage. | ||
atoms measureNameAtom percentAtom | ||
extends abstractNumericMeasureParser | ||
example | ||
ownershipParser | ||
extends abstractPercentageMeasureParser | ||
id Breck | ||
ownership 31.8 | ||
javascript | ||
get measureValue() { | ||
const {content} = this | ||
return content === undefined ? "" : parseFloat(content) | ||
} | ||
|
||
|
||
// Enum Measures | ||
abstractEnumMeasureParser | ||
description A single enum. | ||
atoms measureNameAtom enumAtom | ||
extends abstractMeasureParser | ||
example | ||
favoriteHtmlTagParser | ||
extends abstractEnumMeasureParser | ||
atoms measureNameAtom htmlTagAtom | ||
id Breck | ||
favoriteHtmlTag 2020 | ||
|
||
// Boolean Measures | ||
abstractBooleanMeasureParser | ||
description A single boolean. | ||
atoms measureNameAtom booleanAtom | ||
extends abstractMeasureParser | ||
example | ||
hasBillOfRightsParser | ||
extends abstractBooleanMeasureParser | ||
id USA | ||
hasBillOfRights true | ||
javascript | ||
get measureValue() { | ||
const {content} = this | ||
return content === undefined ? "" : content == "true" | ||
} | ||
|
||
// Date and time measures | ||
abstractDateMeasureParser | ||
description Year/month/day in ISO 8601, US, European formats. | ||
atoms measureNameAtom dateAtom | ||
extends abstractMeasureParser | ||
string typeForWebForms date | ||
javascript | ||
get measureValue() { | ||
const {content} = this | ||
if (!content) return "" | ||
const {dayjs} = this.root | ||
try { | ||
// First try parsing with dayjs | ||
const parsed = dayjs(content) | ||
if (parsed.isValid()) | ||
return parsed.format("YYYY-MM-DD") | ||
// Try parsing other common formats | ||
const formats = [ | ||
"MM/DD/YYYY", | ||
"DD/MM/YYYY", | ||
"YYYY/MM/DD", | ||
"MM-DD-YYYY", | ||
"DD-MM-YYYY", | ||
"YYYY-MM-DD", | ||
"DD.MM.YYYY", | ||
"YYYY.MM.DD" | ||
] | ||
for (const format of formats) { | ||
const attempt = dayjs(content, format) | ||
if (attempt.isValid()) | ||
return attempt.format("YYYY-MM-DD") | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
return "" | ||
} | ||
return "" | ||
} | ||
get valueAsTimestamp() { | ||
const {measureValue} = this | ||
return measureValue ? this.root.dayjs(measureValue).unix() : "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters