Skip to content

Instantly share code, notes, and snippets.

@DominicWatson
Last active March 6, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicWatson/d6ce9527fa3294b286cc to your computer and use it in GitHub Desktop.
Save DominicWatson/d6ce9527fa3294b286cc to your computer and use it in GitHub Desktop.
<cfscript>
struct function stripNonDataNgAndJsAttributes( required struct attributes ) {
var patternToKeep = "^((data|ng)\-|on)\S";
return attributes.filter( function( key, value ){
return key.reFindNoCase( patternToKeep );
} );
}
string function structToQueryString( required struct input ) {
return input.reduce( function( result, key, value ){
return result & ' #key.lCase()#="#value.encodeForHTMLAttribute()#"';
}, "" );
}
attributes = {
"data-test" = "test"
, "ng-dang" = "fubar"
, "onSubmit" = "yes"
, test = 0
};
filtered = stripNonDataNgAndJsAttributes( attributes );
qs = structToQueryString( filtered );
WriteOutput( qs );
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment