@@ -83,18 +83,32 @@ 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 ) => {
92
+ return string1 . localeCompare ( string2 , undefined , { sensitivity : 'accent' } ) === 0 ;
93
+ } ;
94
+
95
+ // This is purely intended to conform to DCP website's zoning district URL scheme.
96
+ // Originally added to make it possible to link out to DCP website:
97
+ // https://github.com/NYCPlanning/labs-zola/commit/889cd2ddaf8b17f37a977fb5f84409e3c5535695
86
98
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 ;
99
+ if ( ! primaryzone ) return ;
100
+
101
+ let code = primaryzone . match ( / \w \d * / ) [ 0 ] . toLowerCase ( ) ;
102
+
103
+ // Check case insensitive similarity because zoning codes are represented either
104
+ // capitalized or otherwise
105
+ if ( isSimilar ( primaryzone , 'c1' ) || isSimilar ( primaryzone , 'c2' ) ) {
106
+ code = 'c1-c2' ;
107
+ } else if ( isSimilar ( primaryzone , 'c3' ) ) {
108
+ code = 'c3-c3a' ;
95
109
}
96
110
97
- return url ;
111
+ return code ;
98
112
} ;
99
113
100
114
const { attr } = DS ;
@@ -105,14 +119,12 @@ export default class ZoningDistrictFragment extends MF.Fragment {
105
119
@attr ( 'string' )
106
120
zonedist ;
107
121
122
+ // Used to clean up the 'zonedist' field to build a URL to the DCP website
108
123
@computed ( 'zonedist' )
109
- get primaryzone ( ) {
124
+ get dcpWebsiteFileName ( ) {
110
125
const zonedist = this . get ( 'zonedist' ) ;
111
126
112
- // convert R6A to r6
113
- const primary = handleCommercialZoningExceptions ( zonedist . match ( / \w \d * / ) [ 0 ] . toLowerCase ( ) ) ;
114
-
115
- return primary ;
127
+ return handleCommercialZoningExceptions ( zonedist ) ;
116
128
}
117
129
118
130
@computed ( 'zonedist' )
0 commit comments