Skip to content

Commit

Permalink
Add: name option to all textSplit funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Nov 14, 2023
1 parent 50709d9 commit 1fbef39
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/functions/misc/editTextSplitElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [index, text] = data.inside.splits;
let [name, index, text] = data.inside.splits;
data.function = d.func;
index = index - 1;

Expand All @@ -14,7 +14,7 @@ module.exports = async (d) => {
"Invalid Index Provided In",
);

d.array[index] = text;
d.array[name][index] = text;

return {
code: d.util.setCode(data),
Expand Down
4 changes: 2 additions & 2 deletions src/functions/misc/findTextSplitIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module.exports = async d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [query] = data.inside.splits;
const [name, query] = data.inside.splits;

data.result = d.array.indexOf(query) + 1;
data.result = d.array[name].indexOf(query) + 1;

return {
code: d.util.setCode(data)
Expand Down
4 changes: 2 additions & 2 deletions src/functions/misc/joinSplitText.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module.exports = d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const sep = data.inside.inside;
const [name, sep = ' '] = data.inside.inside;

data.result = d.array.join(sep.addBrackets());
data.result = d.array[name].join(sep.addBrackets());

return {
code: d.util.setCode(data, false)
Expand Down
6 changes: 3 additions & 3 deletions src/functions/misc/removeSplitTextElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module.exports = d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [...elements] = data.inside.splits;
const [name, ...elements] = data.inside.splits;

for (const element of elements) {
const index = d.array.indexOf(element.addBrackets());
const index = d.array[name].indexOf(element.addBrackets());

if (index !== -1) {
d.array.splice(index, 1);
d.array[name].splice(index, 1);
}
}
d.data.array = d.array;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/misc/removeTextSplitElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module.exports = d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [element] = data.inside.splits;
const [name, element] = data.inside.splits;

const index = d.array.indexOf(element.addBrackets());
const index = d.array[name].indexOf(element.addBrackets());

if (index !== -1) {
d.array.splice(index, 1);
d.array[name].splice(index, 1);
}

d.data.array = d.array;
Expand Down
4 changes: 2 additions & 2 deletions src/functions/util/concatTextSplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module.exports = async d => {
const err = d.inside(inside);
if (err) return d.error(err);

let [...text] = inside.splits;
let [name, ...text] = inside.splits;
text = text.map(x => x.addBrackets());
d.array.concat(text)
d.array[name].concat(text)

return {
code: d.util.setCode({function: d.func, code, inside}),
Expand Down
10 changes: 5 additions & 5 deletions src/functions/util/filterTextSplitElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ module.exports = async d => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let [query, type = "equal", separator = ","] = data.inside.splits;
let [name, query, type = "equal", separator = ","] = data.inside.splits;
if (!["equal", "starts", "ends", "includes"].includes(type)) return d.aoiError.fnError(d, "custom", {inside: data.inside}, `Invalid Type Provided In`);

switch (type) {
case "equal" :
data.result = d.array.filter(x => x === query)
data.result = d.array[name].filter(x => x === query)
break;
case "starts":
data.result = d.array.filter(x => x.startsWith(query))
data.result = d.array[name].filter(x => x.startsWith(query))
break;
case "ends" :
data.result = d.array.filter(x => x.endsWith(query))
data.result = d.array[name].filter(x => x.endsWith(query))
break;
case "includes":
data.result = d.array.filter(x => x.includes(query))
data.result = d.array[name].filter(x => x.includes(query))
break;
}

Expand Down
5 changes: 4 additions & 1 deletion src/functions/util/getTextSplitLength.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module.exports = d => {
const {code} = d.util.aoiFunc(d);
const inside = d.unpack();

let [name] = inside.splits;

return {
code: d.util.setCode({function: d.func, code, result: d.array.length})
code: d.util.setCode({function: d.func, code, result: d.array[name].length})
}
}
4 changes: 2 additions & 2 deletions src/functions/util/textSplitMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Interpreter = require("../../core/interpreter.js");
module.exports = async (d) => {
const data = d.util.aoiFunc(d);

let commands = data.inside.splits;
let [name, commands] = data.inside.splits;
const content = [];

if (
Expand All @@ -21,7 +21,7 @@ module.exports = async (d) => {
"Invalid Awaited Command In",
);

for (const a of d.array) {
for (const a of d.array[name]) {
for (const command of commands) {
const cmd = d.client.cmd.awaited.find(
(y) => y.name.toLowerCase() === command.trim().toLowerCase(),
Expand Down

0 comments on commit 1fbef39

Please sign in to comment.