import { Singleton, Container, Scope, Inject } from "typescript-ioc";

@Singleton
export class DbUtil {

    static underline2Hump(s: any) {
        return s.replace(/_(\w)/g, function (all, letter) {
            return letter.toUpperCase()
        })
    }

    static jsonToHump(obj: any) {
        if (obj instanceof Array) {
            obj.forEach(function (v, i) {
                DbUtil.jsonToHump(v)
            })
        } else if (obj instanceof Object) {
            Object.keys(obj).forEach(function (key) {
                var newKey = DbUtil.underline2Hump(key)
                if (newKey !== key) {
                    obj[newKey] = obj[key]
                    delete obj[key]
                }
                DbUtil.jsonToHump(obj[newKey])
            })
        }
        return obj
    }
}