Javascript to create immutableid


I need to be able to fetch and convert AD users Guid to immutableID and put it in a virtual attribute, my thought is that it should be possible to do with advanced java script in virtual attributes, but I haven't found any script that can do that. Have somebody don that and have a script to share it should be much appreciated-