/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/usermode@1.1.9/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Usermode=void 0;var tslib_1=require("tslib"),_window=global.window||{require:require},fs=_window.require("fs"),path=_window.require("path"),sha=require("js-sha512").sha512_256,Usermode=function(){function e(){}return e.init=function(e){fs.existsSync(e)||fs.writeFileSync(e,"{}"),this.filepath=e,this.users=this.readFile(),this.dirpath=path.dirname(this.filepath)},e.readFile=function(){return JSON.parse(fs.readFileSync(this.filepath).toString())},e.writeFile=function(){fs.writeFileSync(this.filepath,JSON.stringify(this.users))},e.getUser=function(e){return this.users[e]},e.addUser=function(e){var s=sha(e.password);if(this.getUser(e.username))throw new Error('Username "'.concat(e.username,'" already exists!'));return this.users[e.username]={username:e.username,password:s,fullname:e.fullname},this.writeFile(),this.users[e.username]},e.setUser=function(e,s){var r=this.getUser(e.username),t={};if(!r)throw new Error('Username "'.concat(e.username,'" does not exist!'));if(r.password!==e.password&&!s.__force)throw new Error('Password "'.concat(e.password,'" does not match!'));return t.password=s.password?sha(s.password):r.password,t.fullname=s.fullname||r.fullname,this.users[e.username]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},t),{username:r.username}),this.writeFile(),this.users[e.username]},e.setHome=function(e){var s=path.join(this.dirpath,e);return fs.existsSync(s)||fs.mkdirSync(s),s},e.getHome=function(e){var s=path.join(this.dirpath,e);if(fs.existsSync(s))return s},e.passMatch=function(e,s){var r=this.getUser(e);if(!r)throw new Error('Username "'.concat(e,'" does not exist!'));return r.password===sha(s)},e}();exports.Usermode=Usermode;
//# sourceMappingURL=/sm/8b05ab94c37f7e6c49c6a12a91ca17396c3a86dd39e03bac35a549a3d03f9b43.map