HumanCase ( str )
For converting common developer naming conventions to human friendly text.
Be the first to rate this function Log in to vote
|
Josh Ormond - Show more from this author
Iozax, LLC http://iozax.com |
HumanCase ( "xmlParser" )
HumanCase ( GetFieldName ( apiLog::id ) )
HumanCase ( apiLog::label ) // label = "shopify"
XML Parser
API Log: ID
Shopify
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Special Thanks: Josh Willing Halpern. This is a wonderfully helpful convenience function.
For those times when you want to just display your developer conventions in a human friendly way. Handle snake_case, camelCase, fully qualified field names, and preserves some common abbreviations.
Here are some tests that you can throw into your data viewer with the custom function installed to make sure any changes function as you expect, after you make any changes.
/* UNIT TESTS - copy into the data viewer */
While (
[
_showPassed = true ;
_tests = JSONSetElement ( "[]" ;
[ "[+].input" ; "snake_case" ; JSONString ] ;
[ "[:].expected" ; "Snake Case" ; JSONString ] ;
[ "[+].input" ; "camelCase" ; JSONString ] ;
[ "[:].expected" ; "Camel Case" ; JSONString ] ;
[ "[+].input" ; "mixed_case_WithBoth__And_Other Stuff" ; JSONString ] ;
[ "[:].expected" ; "Mixed Case With Both And Other Stuff" ; JSONString ] ;
// plain values
[ "[+].input" ; "shopify" ; JSONString ] ;
[ "[:].expected" ; "Shopify" ; JSONString ] ;
// acronyms in camelCase
[ "[+].input" ; "logAPI" ; JSONString ] ;
[ "[:].expected" ; "Log API" ; JSONString ] ;
[ "[+].input" ; "XMLParser" ; JSONString ] ;
[ "[:].expected" ; "XML Parser" ; JSONString ] ;
[ "[+].input" ; "xmlParser" ; JSONString ] ;
[ "[:].expected" ; "XML Parser" ; JSONString ] ;
[ "[+].input" ; "userIDNumber" ; JSONString ] ;
[ "[:].expected" ; "User ID Number" ; JSONString ] ;
[ "[+].input" ; "address2Line" ; JSONString ] ;
[ "[:].expected" ; "Address2 Line" ; JSONString ] ;
// all caps
[ "[+].input" ; "FIRST_NAME" ; JSONString ] ;
[ "[:].expected" ; "First Name" ; JSONString ] ;
[ "[+].input" ; "USER_API_KEY" ; JSONString ] ;
[ "[:].expected" ; "User API Key" ; JSONString ] ;
[ "[+].input" ; "PDF_ID" ; JSONString ] ;
[ "[:].expected" ; "PDF ID" ; JSONString ] ;
[ "[+].input" ; "API_API" ; JSONString ] ;
[ "[:].expected" ; "API API" ; JSONString ] ;
[ "[+].input" ; "APIARY_COUNT" ; JSONString ] ;
[ "[:].expected" ; "Apiary Count" ; JSONString ] ;
// all caps checked per part (TO must not exist in this file)
[ "[+].input" ; "NOTATABLE::id" ; JSONString ] ;
[ "[:].expected" ; "Notatable: ID" ; JSONString ] ;
[ "[+].input" ; "Contact::FIRST_NAME" ; JSONString ] ;
[ "[:].expected" ; "Contact: First Name" ; JSONString ] ;
// known abbreviations in lowercase input
[ "[+].input" ; "jsonLog" ; JSONString ] ;
[ "[:].expected" ; "JSON Log" ; JSONString ] ;
[ "[+].input" ; "userId" ; JSONString ] ;
[ "[:].expected" ; "User ID" ; JSONString ] ;
[ "[+].input" ; "api_key" ; JSONString ] ;
[ "[:].expected" ; "API Key" ; JSONString ] ;
[ "[+].input" ; "jsonAPIResponse" ; JSONString ] ;
[ "[:].expected" ; "JSON API Response" ; JSONString ] ;
[ "[+].input" ; "apiaryCount" ; JSONString ] ;
[ "[:].expected" ; "Apiary Count" ; JSONString ] ;
// Real base table: the TO name is swapped for the base table name and "::" is a separator. TODO: replace this field for a real table and field in your file to test.
[ "[+].input" ; "CON__Contact::firstName" ; JSONString ] ;
[ "[:].expected" ; "Contact: First Name" ; JSONString ] ;
// no base table: the TO name is kept and "::" is a separator
[ "[+].input" ; "HTTP::Log" ; JSONString ] ;
[ "[:].expected" ; "HTTP: Log" ; JSONString ] ;
[ "[+].input" ; "fake_table::someField" ; JSONString ] ;
[ "[:].expected" ; "Fake Table: Some Field" ; JSONString ]
) ;
_i = 0 ;
_count = ValueCount ( JSONListKeys ( _tests ; "" ) ) ;
_res = ""
] ;
_i < _count ;
[
_input = JSONGetElement ( _tests ; "[" & _i & "].input" ) ;
_expected = JSONGetElement ( _tests ; "[" & _i & "].expected" ) ;
_actual = HumanCase ( _input ) ;
_pass = Exact ( _expected ; _actual ) ;
_passOrFail = If ( _pass ; "pass" ; "FAIL" ) ;
_res = If (
_pass = False or _showPassed ;
List ( _res ;
_passOrFail
& " - " & _input
& If ( not _pass ; "¶ expected: " & _expected )
& If ( not _pass ; "¶ actual: " & _actual )
) ;
_res
) ;
_i = _i + 1
] ;
_res
)
Comments
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.