@@ -83,18 +83,30 @@ const zoningAbbr = {
83
83
BPC : 'bpc' ,
84
84
} ;
85
85
86
+ // Performs case insensitive string equality check.
87
+ // Uses "accent" level sensitivity:
88
+ // "accent": Only strings that differ in base letters or accents and other diacritic marks compare as unequal.
89
+ // Examples: a ≠ b, a ≠ á, a = A.
90
+ // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#parameters.
91
+ const isSimilar = ( string1 , string2 ) => string1 . localeCompare ( string2 , undefined , { sensitivity : 'accent' } ) === 0 ;
92
+
93
+ // This is purely intended to conform to DCP website's zoning district URL scheme.
94
+ // Originally added to make it possible to link out to DCP website:
95
+ // https://github.com/NYCPlanning/labs-zola/commit/889cd2ddaf8b17f37a977fb5f84409e3c5535695
86
96
export const handleCommercialZoningExceptions = ( primaryzone ) => {
87
- let url = '' ;
88
-
89
- if ( ( primaryzone === 'c1' ) || ( primaryzone === 'c2' ) ) {
90
- url = 'c1-c2' ;
91
- } else if ( primaryzone === 'c3' ) {
92
- url = 'c3-c3a' ;
93
- } else {
94
- url = primaryzone ;
97
+ if ( ! primaryzone ) return '' ;
98
+
99
+ let code = primaryzone . match ( / \w \d * / ) [ 0 ] . toLowerCase ( ) ;
100
+
101
+ // Check case insensitive similarity because zoning codes are represented either
102
+ // capitalized or otherwise
103
+ if ( isSimilar ( primaryzone , 'c1' ) || isSimilar ( primaryzone , 'c2' ) ) {
104
+ code = 'c1-c2' ;
105
+ } else if ( isSimilar ( primaryzone , 'c3' ) ) {
106
+ code = 'c3-c3a' ;
95
107
}
96
108
97
- return url ;
109
+ return code ;
98
110
} ;
99
111
100
112
const { attr } = DS ;
@@ -105,14 +117,12 @@ export default class ZoningDistrictFragment extends MF.Fragment {
105
117
@attr ( 'string' )
106
118
zonedist ;
107
119
120
+ // Used to clean up the 'zonedist' field to build a URL to the DCP website
108
121
@computed ( 'zonedist' )
109
- get primaryzone ( ) {
122
+ get dcpWebsiteFileName ( ) {
110
123
const zonedist = this . get ( 'zonedist' ) ;
111
124
112
- // convert R6A to r6
113
- const primary = handleCommercialZoningExceptions ( zonedist . match ( / \w \d * / ) [ 0 ] . toLowerCase ( ) ) ;
114
-
115
- return primary ;
125
+ return handleCommercialZoningExceptions ( zonedist ) ;
116
126
}
117
127
118
128
@computed ( 'zonedist' )
0 commit comments