SS 2.0 has the N/encode module that does this for ...
# suitescript
m
SS 2.0 has the N/encode module that does this for you.