Skip to content

Commit

Permalink
Lint, regenerate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
SKaplanOfficial committed Dec 27, 2023
1 parent 4ab1fab commit 6ee79a7
Show file tree
Hide file tree
Showing 170 changed files with 518 additions and 444 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@raycast"]
}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Placeholders Toolkit Changelog

## [0.1.3] - 2023-11-15?
## [0.1.3] - 2023-12-26

- Re-added the `{{selectedFileContents}}` (or just `{{contents}}`) placeholder.
- Deprecated `PLApplicator.checkForPlaceholders()` in favor of `PLChecker.checkForPlaceholders()`.
- Added `PLChecker.checkForPlaceholdersInRange()` and `PLChecker.getPlaceholderRanges()`.
- Added optional `offsets` parameter to `{{clipboardText}}`, allowing users to specify one or more previous clipboard items to return.
- Fixed bug where `{{fileNames}}` would only return the last file name.

## [0.1.2] - 2023-11-11
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,11 @@ m4: /{{url(\s*?(raw=(true|false))?):((?:(?:(?:https?):)\/\/)(?:\S+(?::\S*)?@)?(?
```

Although these regexes match *mostly* the same strings, the latter two aim to match the URL standard (i.e. RFC 3986) more closely. You might not need the extra precision for your use case, so it's up to you to decide which style to use.

## Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

## License

This project is licensed under the MIT License.
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/enums/PlaceholderCategory.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/enums/PlaceholderType.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLApplicator.applyToObjectValueWithKey.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLApplicator.applyToObjectValuesWithKeys.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLApplicator.applyToString.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLApplicator.applyToStrings.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLApplicator.bulkApply.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/functions/PLApplicator.checkForPlaceholders.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/functions/PLChecker.checkForPlaceholders.html

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions docs/functions/PLChecker.checkForPlaceholdersInRange.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/functions/PLChecker.getPlaceholderRanges.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLCreator.buildPlaceholdersFromFnDict.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLCreator.buildPlaceholdersFromValueDict.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLCreator.dummyPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLCreator.newPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLLoader.loadPlaceholderFromJSONString.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLLoader.loadPlaceholdersFromFile.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLLoader.loadPlaceholdersFromJSONString.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.Bool.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.Braced.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.Container.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.EmailAddress.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.Float.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.HTTPURL.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.InnerText.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.Integer.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.List.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.QuotedParameter.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.RawParameter.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLMatcher.URI.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireActiveBrowser.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireContainedIn.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireContains.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireEquals.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireNotEquals.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/PLRule.RequireValue.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getActiveBrowser.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getExtensions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getJSONResponse.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getMatchingYouTubeVideoID.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getTextOfWebpage.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getURLHTML.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getWeatherData.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getYouTubeVideoTranscriptById.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.getYouTubeVideoTranscriptByURL.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/functions/utils.runJSInActiveTab.html

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/modules.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/modules/PLApplicator.html

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/modules/PLChecker.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/PLCreator.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/PLLoader.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/PLMatcher.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/PLRule.html

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/modules/Placeholders.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/utils.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/types/CustomPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/types/PLMatcher.braceType.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/types/PLRange.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/types/Placeholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/DefaultPlaceholders.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.AlertDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.AppleScriptPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.AudioDirectives.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.AudioFlowDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ChooseApplicationDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ChooseFileDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ChooseFolderDirective.html

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/variables/Placeholders.ClipboardTextPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CommandPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ComputerNamePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CopyDirective.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentAppNamePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentAppPathPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentDirectoryPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentTabTextPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentTrackPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CurrentURLPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.CutoffDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.DatePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.DayPlaceholder.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.DialogDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ElementHTMLPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ElementTextPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.FileMetadataPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.FileNamesPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.FilePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.FocusedElementPlaceholder.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.HomeDirPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.HostnamePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.IgnoreDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ImageDirectives.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ImageFlowDirective.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.JXAPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.JavaScriptPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.LastEmailPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.LastNotePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.LocationPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.MonthEventsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.MonthRemindersPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.MusicTracksPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.NearbyLocationsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.PDFFlowDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.PasteDirective.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SafariBookmarksPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SafariTopSitesPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SayDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SelectFileDirective.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SelectedFilesPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SelectedTextPlaceholder.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ShellScriptPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ShortcutPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ShortcutsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.SystemLanguagePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TextFileDirectives.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TextFileFlowDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TimePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TimezonePlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.ToastDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TodayEventsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TodayRemindersPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TodayWeatherPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.TypeDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.URLPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.UUIDPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.UsedUUIDsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.UserPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.VarsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.VideoDirectives.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.VideoFlowDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.WeekEventsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.WeekRemindersPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.WeekWeatherPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.WriteFileDirective.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.YearEventsPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.YearRemindersPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/Placeholders.YouTubeTranscriptPlaceholder.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/variables/utils.SupportedBrowsers.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/directives/selectFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const SelectFileDirective: Placeholder = {
name: "selectFile",
regex: /{{(selectFile)(:[\s\S]*?)?}}/g,
apply: async (str: string) => {
const file = str.match(/(?<=(selectFiles:))[\s\S]*?(?=}})/)?.[0];
const file = str.match(/(?<=(selectFile:))[\s\S]*?(?=}})/)?.[0];
if (!file) return { result: "" };
await addFileToSelection(file);
return { result: "" };
Expand Down
1 change: 0 additions & 1 deletion lib/directives/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Placeholder, PlaceholderCategory, PlaceholderType } from "../types";
import * as fs from "fs";
import os from "os";
import path from "path";
import { AlertDirective } from "../placeholders";

/**
* Directive to write the provided text to a file. The placeholder will always be replaced with an empty string.
Expand Down
62 changes: 49 additions & 13 deletions lib/info-placeholders/clipboardText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,68 @@ import { Clipboard } from "@raycast/api";
import { Placeholder, PlaceholderCategory, PlaceholderType } from "../types";
import { RequireValue } from "../rules";

enum EntriesSpecifierType {
Range = "range",
List = "list",
}

/**
* Placeholder for the text currently stored in the clipboard. If the clipboard is empty, this will be replaced with an empty string. Most clipboard content supplies a string format, such as file names when copying files in Finder.
*
* Syntax: `{{clipboardText}}`
* If the `offsets` parameter is provided, the placeholder will be replaced with a list of one or more previous clipboard text entries separated by newlines. The `offsets` parameter can be a list of numbers or a range of numbers, e.g. `1, 2, 3`, `1-3`, and `1..3` are all treated equally. If the `offsets` parameter is not provided, the placeholder will be replaced with the text currently stored in the clipboard. To include the current clipboard text in addition to previous entries, begin the list with `0`.
*
* Syntax: `{{clipboardText}}` or `{{clipboardText offsets=[1, 2, 3]}}` or `{{clipboardText offsets=[1..3]}}`
*/
const ClipboardTextPlaceholder: Placeholder = {
name: "clipboardText",
regex: /{{(clipboardText|clipboard)}}/g,
apply: async (_, context?: { [key: string]: unknown }) => {
if (context?.["clipboardText"]?.toString().length) {
return {
result: context["clipboardText"] as string,
clipboardText: context["clipboardText"],
};
regex:
/{{(clipboardText|clipboard)( offsets=((([0-9])((-|\.\.)([0-9]*)|(, ?[0-9]+)*))|\[(([0-9])((-|\.\.)([0-9]*)|(, ?[0-9]+)*))\]))?}}/g,
apply: async (str: string) => {
const matches = str.match(
/{{(clipboardText|clipboard)( offsets=((([0-9])((-|\.\.)([0-9]*)|(, ?[0-9]+)*))|\[(([0-9])((-|\.\.)([0-9]*)|(, ?[0-9]+)*))\]))?}}/
);
if (!matches) {
return { result: "" };
}

const entries = matches[3];
const offsets = [];

if (entries) {
const specifierType = entries.includes("-") || entries.includes("..")
? EntriesSpecifierType.Range
: EntriesSpecifierType.List;
if (specifierType === EntriesSpecifierType.Range) {
const range = entries.replaceAll(/(\[|\])/g, "").split(/(-|\.\.)/)
const start = parseInt(range[0]);
const end = parseInt(range[2]);
for (let i = start; i <= end; i++) {
offsets.push(i);
}
} else {
const list = entries.replaceAll(/(\[|\])/g, "").split(",");
for (const entry of list) {
offsets.push(parseInt(entry.trim()));
}
}
}

if (offsets.length === 0) {
offsets.push(0);
}

try {
const text = (await Clipboard.readText()) || "";
return { result: text, clipboardText: text };
let text = "";
for (const offset of offsets) {
text += `\n${(await Clipboard.readText({ offset })) || ""}`;
}
return { result: text.trim() };
} catch (e) {
return { result: "", clipboardText: "" };
return { result: "" };
}
},
rules: [RequireValue(Clipboard.readText)],
result_keys: ["clipboardText"],
constant: true,
constant: false,
fn: async () =>
(await ClipboardTextPlaceholder.apply("{{clipboardText}}")).result,
example: "Summarize this: {{clipboardText}}",
Expand Down
3 changes: 1 addition & 2 deletions lib/info-placeholders/currentURL.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getFrontmostApplication } from "@raycast/api";
import { Placeholder, PlaceholderCategory, PlaceholderType } from "../types";
import { SupportedBrowsers, getActiveBrowser } from "../utils";
import { getActiveBrowser } from "../utils";
import { RequireActiveBrowser } from "../rules";

/**
Expand Down
41 changes: 14 additions & 27 deletions lib/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,38 @@ import {
const validatePlaceholderJSON = (jsonObject: JSONObject): [boolean, string] => {
if (typeof jsonObject !== "object")
return [false, "Placeholder is not an object."];
if (!jsonObject.hasOwnProperty("name"))
if ("name" in jsonObject === false)
return [false, "Placeholder is missing name field."];
if (!jsonObject.hasOwnProperty("value"))
if ("value" in jsonObject === false)
return [false, "Placeholder is missing value field."];

if (typeof jsonObject.name !== "string")
return [false, "Placeholder name is not a string."];
if (typeof jsonObject.value !== "string")
return [false, "Placeholder value is not a string."];

if (
jsonObject.hasOwnProperty("regex") &&
typeof jsonObject.regex !== "string"
)
if ("regex" in jsonObject && typeof jsonObject.regex !== "string")
return [false, "Placeholder regex is not a string."];
if (
jsonObject.hasOwnProperty("description") &&
typeof jsonObject.description !== "string"
)
if ("description" in jsonObject && typeof jsonObject.description !== "string")
return [false, "Placeholder description is not a string."];
if (
jsonObject.hasOwnProperty("example") &&
typeof jsonObject.example !== "string"
)
if ("example" in jsonObject && typeof jsonObject.example !== "string")
return [false, "Placeholder example is not a string."];
if (
jsonObject.hasOwnProperty("hintRepresentation") &&
"hintRepresentation" in jsonObject &&
typeof jsonObject.hintRepresentation !== "string"
)
return [false, "Placeholder hintRepresentation is not a string."];
if (
jsonObject.hasOwnProperty("fullRepresentation") &&
"fullRepresentation" in jsonObject &&
typeof jsonObject.fullRepresentation !== "string"
)
return [false, "Placeholder fullRepresentation is not a string."];
if (jsonObject.hasOwnProperty("type") && typeof jsonObject.type !== "number")
if ("type" in jsonObject && typeof jsonObject.type !== "number")
return [false, "Placeholder type is not a number."];
if (
jsonObject.hasOwnProperty("categories") &&
!Array.isArray(jsonObject.categories)
)
if ("categories" in jsonObject && !Array.isArray(jsonObject.categories))
return [false, "Placeholder categories is not an array."];
if (
jsonObject.hasOwnProperty("categories") &&
"categories" in jsonObject &&
(jsonObject.categories as unknown[]).some(
(category) => typeof category !== "number"
)
Expand Down Expand Up @@ -89,7 +77,7 @@ export const loadPlaceholderFromJSONString = (
newPlaceholderData.regex || `{{${newPlaceholderData.name}}}`
),
rules: [],
apply: async (str: string, context?: { [key: string]: unknown }) => {
apply: async (str: string) => {
const match = str.match(new RegExp(`${newPlaceholderData.regex}`));
let value = newPlaceholderData.value;
(match || []).forEach((m, index) => {
Expand All @@ -106,7 +94,7 @@ export const loadPlaceholderFromJSONString = (
},
result_keys: [newPlaceholderData.name],
constant: true,
fn: async (content: string) =>
fn: async () =>
(await newPlaceholder.apply(`{{${newPlaceholderData.name}}}`)).result,
description: newPlaceholderData.description || "",
example: newPlaceholderData.example || "",
Expand Down Expand Up @@ -161,7 +149,7 @@ export const loadPlaceholdersFromJSONString = (
name: placeholder.name,
regex: new RegExp(`${key}`),
rules: [],
apply: async (str: string, context?: { [key: string]: unknown }) => {
apply: async (str: string) => {
const match = str.match(new RegExp(`${key}`));
let value = placeholder.value;
(match || []).forEach((m, index) => {
Expand All @@ -178,8 +166,7 @@ export const loadPlaceholdersFromJSONString = (
},
result_keys: [placeholder.name],
constant: true,
fn: async (content: string) =>
(await newPlaceholder.apply(`{{${key}}}`)).result,
fn: async () => (await newPlaceholder.apply(`{{${key}}}`)).result,
description: placeholder.description,
example: placeholder.example,
hintRepresentation: placeholder.hintRepresentation,
Expand Down
30 changes: 15 additions & 15 deletions lib/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export const InnerText = (options?: {
}) => {
const global = options?.global ?? true;
if (options?.braceType == undefined || options?.braceType === "curly")
return new RegExp(`(([^{]|{(?!{)|{{[\s\S]*?}})*?)`, global ? "g" : "");
return new RegExp(`(([^{]|{(?!{)|{{[\\s\\S]*?}})*?)`, global ? "g" : "");
else if (options?.braceType == "square")
return new RegExp(
`(([^\[]|\[(?!\[)|\[\[\s\S]*?\]\])*?)`,
`(([^\\[]|\\[(?!\\[)|\\[\\[\\s\\S]*?\\]\\])*?)`,
global ? "g" : ""
);
else if (options?.braceType == "round")
return new RegExp(
`(([^(]|\((?!\()|\(\([\s\S]*?\)\))*?)`,
`(([^(]|\\((?!\\()|\\(\\([\\s\\S]*?\\)\\))*?)`,
global ? "g" : ""
);
else if (options?.braceType == "angle")
return new RegExp(`(([^<]|<(?!<)|<<[\s\S]*?>>)*?)`, global ? "g" : "");
return new RegExp(`(([^<]|<(?!<)|<<[\\s\\S]*?>>)*?)`, global ? "g" : "");
else throw new Error(`Unknown brace type ${options.braceType}`);
};

Expand Down Expand Up @@ -161,16 +161,16 @@ export const Braced = (
);
else if (options?.braceType == "square")
return new RegExp(
`\[\[(${
`\\[\\[(${
innerMatch instanceof RegExp ? innerMatch.source : innerMatch
})\]\]`,
})\\]\\]`,
global ? "g" : ""
);
else if (options?.braceType == "round")
return new RegExp(
`\(\((${
`\\(\\((${
innerMatch instanceof RegExp ? innerMatch.source : innerMatch
})\)\)`,
})\\)\\)`,
global ? "g" : ""
);
else if (options?.braceType == "angle")
Expand Down Expand Up @@ -223,20 +223,20 @@ export const Container = (
);
else if (options?.braceType == "square")
return new RegExp(
`\[\[${name}(\\s*?${parameters
`\\[\\[${name}(\\s*?${parameters
.map((p) => (p instanceof RegExp ? p.source : p))
.join("\\s*?")}):(${
valueType instanceof RegExp ? valueType.source : valueType
})\]\]`,
})\\]\\]`,
global ? "g" : ""
);
else if (options?.braceType == "round")
return new RegExp(
`\(\(${name}(\\s*?${parameters
`\\(\\(${name}(\\s*?${parameters
.map((p) => (p instanceof RegExp ? p.source : p))
.join("\\s*?")}):(${
valueType instanceof RegExp ? valueType.source : valueType
})\)\)`,
})\\)\\)`,
global ? "g" : ""
);
else if (options?.braceType == "angle")
Expand Down Expand Up @@ -267,7 +267,7 @@ export const Container = (
*/
export const EmailAddress = (global = true) =>
new RegExp(
/(?=[a-z0-9@.!#$%&'*+\/=?^_`{|}~-]{6,254})(?=[a-z0-9.!#$%&'*+\/=?^_`{|}~-]{1,64}@)[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?=[a-z0-9-]{1,63})[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/,
/(?=[a-z0-9@.!#$%&'*+\\/=?^_`{|}~-]{6,254})(?=[a-z0-9.!#$%&'*+\\/=?^_`{|}~-]{1,64}@)[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*@(?:(?=[a-z0-9-]{1,63}\.)[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?=[a-z0-9-]{1,63})[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/,
global ? "g" : ""
);

Expand All @@ -288,7 +288,7 @@ export const EmailAddress = (global = true) =>
*/
export const URI = (global = true) =>
new RegExp(
/(?:(?:([a-zA-Z0-9]+):)\/?\/?)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9][a-z0-9_-]{0,62})?[a-z0-9]\.)+(?:[a-z]{2,}\.?))(?::\d{2,5})?(?:[\/?#]\S*)?/,
/(?:(?:([a-zA-Z0-9]+):)\/?\/?)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9][a-z0-9_-]{0,62})?[a-z0-9]\.)+(?:[a-z]{2,}\.?))(?::\d{2,5})?(?:[\\/?#]\S*)?/,
global ? "g" : ""
);

Expand All @@ -309,6 +309,6 @@ export const URI = (global = true) =>
*/
export const HTTPURL = (global = true) =>
new RegExp(
/(?:(?:(?:https?):)\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9][a-z0-9_-]{0,62})?[a-z0-9]\.)+(?:[a-z]{2,}\.?))(?::\d{2,5})?(?:[\/?#]\S*)?/,
/(?:(?:(?:https?):)\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9][a-z0-9_-]{0,62})?[a-z0-9]\.)+(?:[a-z]{2,}\.?))(?::\d{2,5})?(?:[\\/?#]\S*)?/,
global ? "g" : ""
);
Loading

0 comments on commit 6ee79a7

Please sign in to comment.