A good start would be using the implementation made in propan: https://github.com/Harium/propan/issues/13