-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from firebase/koss-regexp
Use unquoted RegExp in test function.
- Loading branch information
Showing
12 changed files
with
388 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
changed - Support string.test(/regexp/) format (formerly required regexp in a quoted string). | ||
feature - Added regexp test and samples. | ||
fixed - Parser failed when empty string used. |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
path / { | ||
read() = true; | ||
write() = true; | ||
} | ||
|
||
path /ss is SocialSecurity; | ||
path /integer is IntegerString; | ||
path /float is FloatString; | ||
path /int is Integer; | ||
path /alpha is Alpha; | ||
path /year is Year; | ||
path /date is ISODate; | ||
|
||
type SocialSecurity extends String { | ||
validate() = this.test(/^\d\d\d-\d\d-\d\d\d\d$/); | ||
} | ||
|
||
// Only an integer string | ||
type IntegerString extends String { | ||
validate() = this.test(/^-?\d+$/); | ||
} | ||
|
||
// A floating point number (or integer). | ||
type FloatString extends String { | ||
validate() = this.test(/^-?(\d+\.?\d*|\.\d+)$/); | ||
} | ||
|
||
// An integral number (no fractional part) | ||
type Integer extends Number { | ||
validate() = (this + '').test(/^-?\d+$/); | ||
} | ||
|
||
// Only letters | ||
type Alpha extends String { | ||
validate() = this.test(/^[a-z]+$/i); | ||
} | ||
|
||
// YYYY is 20th or 21st century | ||
type Year extends String { | ||
validate() = this.test(/^(19|20)\d\d$/); | ||
} | ||
|
||
// YYYY-MM-DD in 20th or 21st century | ||
// Note: Does not validate day-of-month is valid. | ||
type ISODate extends String { | ||
validate() = this.test(/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"rules": { | ||
".read": "true", | ||
".write": "true", | ||
"ss": { | ||
".validate": "newData.isString() && newData.val().matches(/^\\d\\d\\d-\\d\\d-\\d\\d\\d\\d$/)" | ||
}, | ||
"integer": { | ||
".validate": "newData.isString() && newData.val().matches(/^-?\\d+$/)" | ||
}, | ||
"float": { | ||
".validate": "newData.isString() && newData.val().matches(/^-?(\\d+\\.?\\d*|\\.\\d+)$/)" | ||
}, | ||
"int": { | ||
".validate": "newData.isNumber() && (newData.val() + '').matches(/^-?\\d+$/)" | ||
}, | ||
"alpha": { | ||
".validate": "newData.isString() && newData.val().matches(/^[a-z]+$/i)" | ||
}, | ||
"year": { | ||
".validate": "newData.isString() && newData.val().matches(/^(19|20)\\d\\d$/)" | ||
}, | ||
"date": { | ||
".validate": "newData.isString() && newData.val().matches(/^(19|20)\\d\\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/)" | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.