66 * @returns {Boolean } - True if a valid name, False if an invalid name
77 */
88function isValidDS2VariableName ( name ) {
9- // Check the general pattern: starts with a letter or underscore, followed by letters, digits, or underscores
10- const identifierPattern = / ^ [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * $ / ;
11- if ( ! identifierPattern . test ( name ) ) {
12- return false ;
13- }
9+ // Check length constraint
10+ if ( typeof name !== "string" || name . length < 1 || name . length > 32 ) {
11+ return false ;
12+ }
1413
15- // Check the length of the pattern
16- if ( name . length > 255 ) {
17- return false ;
18- }
14+ // Reject if starts with more than one underscore
15+ if ( / ^ _ _ / . test ( name ) ) {
16+ return false ;
17+ }
1918
20- // Reserved keywords (converted to lowercase for case-insensitive check)
21- const reservedKeywords = new Set ( [
22- "___kplist" , "_all_" , "_hostname_" , "_new_" , "_localnthreads_" , "_localthreadid_" , "_nthreads_" ,
23- "_null_" , "_rc_" , "_rowset_" , "_temporary_" , "_threadid_" , "abort" , "and" , "as" , "asm" ,
24- "bigint" , "binary" , "by" , "call" , "catalog" , "char" , "character" , "commit" , "continue" ,
25- "data" , "date" , "dcl" , "decimal" , "declare" , "delete" , "descending" , "dim" , "do" , "double" ,
26- "drop" , "ds2_options" , "elif" , "else" , "end" , "enddata" , "endmodule" , "endpackage" ,
27- "endstage" , "endtable" , "endthread" , "eq" , "error" , "escape" , "float" , "format" , "fortran" ,
28- "forward" , "from" , "function" , "ge" , "global" , "goto" , "group" , "gt" , "having" , "identity" ,
29- "if" , "in" , "indsname" , "indsnum" , "informat" , "inline" , "input" , "int" , "integer" , "in_out" ,
30- "keep" , "label" , "le" , "leave" , "like" , "list" , "lt" , "merge" , "method" , "missing" , "modify" ,
31- "module" , "national" , "nchar" , "ne" , "ng" , "nl" , "not" , "null" , "numeric" , "nvarchar" , "ods" ,
32- "of" , "or" , "order" , "other" , "otherwise" , "output" , "overwrite" , "package" , "partition" ,
33- "precision" , "private" , "program" , "put" , "real" , "remove" , "rename" , "replace" , "require" ,
34- "retain" , "return" , "returns" , "rollback" , "select" , "set" , "smallint" , "sqlsub" , "stage" ,
35- "stop" , "stored" , "substr" , "system" , "table" , "then" , "this" , "thread" , "threads" , "time" ,
36- "timestamp" , "tinyint" , "to" , "transaction" , "t_udf" , "tspl_options" , "until" , "update" ,
37- "vararray" , "varbinary" , "varchar" , "varlist" , "varying" , "when" , "where" , "while"
38- ] ) ;
39- return ! reservedKeywords . has ( name . toLowerCase ( ) ) ;
19+ // General identifier pattern: starts with letter or underscore, followed by letters, digits, or underscores
20+ const identifierPattern = / ^ [ A - Z a - z _ ] [ A - Z a - z 0 - 9 _ ] * $ / ;
21+ if ( ! identifierPattern . test ( name ) ) {
22+ return false ;
23+ }
24+
25+ // Reserved keywords (lowercased for case-insensitive comparison)
26+ const reservedKeywords = new Set ( [
27+ "___kplist" , "_all_" , "_hostname_" , "_new_" , "_localnthreads_" , "_localthreadid_" , "_nthreads_" ,
28+ "_null_" , "_rc_" , "_rowset_" , "_temporary_" , "_threadid_" , "abort" , "and" , "as" , "asm" ,
29+ "bigint" , "binary" , "by" , "call" , "catalog" , "char" , "character" , "commit" , "continue" ,
30+ "data" , "date" , "dcl" , "decimal" , "declare" , "delete" , "descending" , "dim" , "do" , "double" ,
31+ "drop" , "ds2_options" , "elif" , "else" , "end" , "enddata" , "endmodule" , "endpackage" ,
32+ "endstage" , "endtable" , "endthread" , "eq" , "error" , "escape" , "float" , "format" , "fortran" ,
33+ "forward" , "from" , "function" , "ge" , "global" , "goto" , "group" , "gt" , "having" , "identity" ,
34+ "if" , "in" , "indsname" , "indsnum" , "informat" , "inline" , "input" , "int" , "integer" , "in_out" ,
35+ "keep" , "label" , "le" , "leave" , "like" , "list" , "lt" , "merge" , "method" , "missing" , "modify" ,
36+ "module" , "national" , "nchar" , "ne" , "ng" , "nl" , "not" , "null" , "numeric" , "nvarchar" , "ods" ,
37+ "of" , "or" , "order" , "other" , "otherwise" , "output" , "overwrite" , "package" , "partition" ,
38+ "precision" , "private" , "program" , "put" , "real" , "remove" , "rename" , "replace" , "require" ,
39+ "retain" , "return" , "returns" , "rollback" , "select" , "set" , "smallint" , "sqlsub" , "stage" ,
40+ "stop" , "stored" , "substr" , "system" , "table" , "then" , "this" , "thread" , "threads" , "time" ,
41+ "timestamp" , "tinyint" , "to" , "transaction" , "t_udf" , "tspl_options" , "until" , "update" ,
42+ "vararray" , "varbinary" , "varchar" , "varlist" , "varying" , "when" , "where" , "while"
43+ ] ) ;
44+
45+ return ! reservedKeywords . has ( name . toLowerCase ( ) ) ;
4046}
0 commit comments