🏴☠️ init
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
root = true
|
||||
|
||||
# for all files
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
# JavaScript
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# Markdown
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @module INI parser
|
||||
* @description ...
|
||||
* @version 1.0.0
|
||||
* @author Alexander Popov <iiiypuk@fastmail.fm>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
function parse(data) {
|
||||
const result = {};
|
||||
const lines = data.split('\n');
|
||||
let section = null;
|
||||
|
||||
lines.forEach((line) => {
|
||||
line = line.trim();
|
||||
if (line.length === 0 || line[0] === ';' || line[0] === '#') return; // Пропустить пустые строки и комментарии
|
||||
|
||||
const sectionMatch = line.match(/^\[(.*)\]$/);
|
||||
if (sectionMatch) {
|
||||
section = sectionMatch[1].trim();
|
||||
result[section] = {};
|
||||
} else {
|
||||
const keyValueMatch = line.match(/^(.*?)=\s*([^#\s]+)/);
|
||||
if (keyValueMatch) {
|
||||
const key = keyValueMatch[1].trim();
|
||||
const value = keyValueMatch[2].trim();
|
||||
|
||||
if (section) {
|
||||
result[section][key] = value;
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = { parse };
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Alexander Popov (https://iiiypuk.me/)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Reference in New Issue
Block a user