mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-15 04:44:47 +08:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { LuciFlied } from "../../../enum/hijpass";
|
|
import uci from "uci";
|
|
|
|
const UciUtils = {
|
|
camelToSnake: function (str: string) {
|
|
return str.replace(/([A-Z])/g, function (match) {
|
|
return '_' + match.toLowerCase();
|
|
});
|
|
},
|
|
|
|
transFromUci: function (object: any, section: any) {
|
|
Object.keys(object).forEach(key => {
|
|
let uciOption = UciUtils.camelToSnake(key)
|
|
if (section[uciOption]) {
|
|
object[key] = section[uciOption]
|
|
}
|
|
});
|
|
},
|
|
|
|
generateUniqueSectionId: function (confName: string = LuciFlied.CONF_NAME) {
|
|
let chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
|
|
for (; ;) {
|
|
result = '';
|
|
for (let i = 0; i < 8; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
|
|
if (!uci.get(confName, result)) {
|
|
break
|
|
}
|
|
}
|
|
|
|
return result;
|
|
},
|
|
};
|
|
|
|
export { UciUtils }
|