generated from vendetta-mod/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96d4fd8
commit 0358710
Showing
6 changed files
with
96 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"build": "node build.mjs" | ||
}, | ||
"dependencies": { | ||
"@swc/helpers": "^0.4.14" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^24.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@swc/core": "^1.3.35", | ||
"esbuild": "^0.16.14", | ||
"rollup": "^3.9.1", | ||
"rollup-plugin-esbuild": "^5.0.0", | ||
"vendetta-types": "latest" | ||
}, | ||
"pnpm": { | ||
"peerDependencyRules": { | ||
"ignoreMissing": [ | ||
"react", | ||
"react-native" | ||
] | ||
} | ||
} | ||
"private": true, | ||
"scripts": { | ||
"build": "node build.mjs", | ||
"test": "tsx tests/index.ts" | ||
}, | ||
"dependencies": { | ||
"@swc/helpers": "^0.4.14" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^24.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.1", | ||
"@swc/core": "^1.3.35", | ||
"@types/node": "^20.2.3", | ||
"esbuild": "^0.16.14", | ||
"rollup": "^3.9.1", | ||
"rollup-plugin-esbuild": "^5.0.0", | ||
"vendetta-types": "latest" | ||
}, | ||
"pnpm": { | ||
"peerDependencyRules": { | ||
"ignoreMissing": [ | ||
"react", | ||
"react-native" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const re = /^[A-Z][a-z']*$/; | ||
|
||
export function decap(text: string) { | ||
if (!text || text.length < 2) return text; | ||
|
||
const out = [] as string[]; | ||
|
||
const words = text.split(" "); | ||
for (let i = 0; i < words.length; i++) { | ||
const word = words[i]; | ||
|
||
const findNextMaybe = (sequence: string) => { | ||
const buf = [word]; | ||
|
||
for (let j = i + 1; j < words.length; j++) { | ||
buf.push(words[j]); | ||
if (words[j].includes(sequence)) { | ||
out.push(...buf); | ||
i = j; | ||
return; | ||
} | ||
} | ||
|
||
out.push(word); | ||
}; | ||
|
||
if (word.startsWith("https://")) out.push(word); | ||
else if (word.startsWith("```")) findNextMaybe("```"); | ||
else if (word.startsWith("`")) findNextMaybe("`"); | ||
else out.push(word.replace(re, m => m.toLowerCase())); | ||
} | ||
|
||
return out.join(" "); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
import { findByProps } from "@vendetta/metro"; | ||
import { before } from "@vendetta/patcher"; | ||
import { decap } from "./decap"; | ||
|
||
const ups = []; | ||
|
||
function bef(obj: any, name: string, cb: (args: any[]) => any) { | ||
ups.push(before(name, obj, cb)); | ||
} | ||
|
||
function decap(msg: { content?: string; }) { | ||
if (!msg?.content) return; | ||
msg.content = msg.content.replace(/\b[A-Z](?=[a-z]*\b)/g, m => m.toLowerCase()); | ||
} | ||
const doDecap = (msg?: { content?: string; }) => msg?.content && (msg.content = decap(msg.content)); | ||
|
||
bef(findByProps("editMessage", "sendMessage"), "sendMessage", args => decap(args[1])); | ||
bef(findByProps("editMessage", "sendMessage"), "sendMessage", args => doDecap(args[1])); | ||
|
||
bef(findByProps("uploadLocalFiles"), "uploadLocalFiles", args => decap(args[0].parsedMessage)); | ||
bef(findByProps("uploadLocalFiles"), "uploadLocalFiles", args => doDecap(args[0].parsedMessage)); | ||
|
||
export const onUnload = () => ups.forEach(up => up()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { decap } from "../plugins/Decap/src/decap"; | ||
import assert from "assert/strict"; | ||
|
||
const cases = { | ||
"F": "F", | ||
"Banana": "banana", | ||
"Some sentence WITH funny CasIng": "some sentence WITH funny CasIng", | ||
"Hi https://google.com/Foo Bye": "hi https://google.com/Foo bye", | ||
"```js\nconst a = 'Hi'``` Bye": "```js\nconst a = 'Hi'``` bye" | ||
}; | ||
|
||
for (const [input, expected] of Object.entries(cases)) { | ||
const actual = decap(input); | ||
assert.equal(actual, expected, `decap("${input}") should be "${expected}" but was "${actual}"`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { readdirSync } from "fs"; | ||
|
||
for (const test of readdirSync(__dirname)) { | ||
if (test !== "index.ts") { | ||
require(`./${test}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"jsx": "react-native", | ||
"allowJs": true | ||
}, | ||
"include": ["plugins", "node_modules/vendetta-types"] | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"jsx": "react-native", | ||
"allowJs": true | ||
}, | ||
"include": ["plugins", "node_modules/vendetta-types", "tests"] | ||
} |