@grammyjs/parse-mode
Advanced tools
Comparing version 1.7.1 to 1.8.0
@@ -102,3 +102,6 @@ import type { MessageEntity } from "./deps.node.js"; | ||
* in further `fmt` tagged templates. | ||
* @param rawStringParts An array of `string` parts found in the tagged template | ||
* | ||
* Can also be called like regular function and passed an array of `Stringable`s. | ||
* | ||
* @param rawStringParts An array of `string` parts found in the tagged template (can also be `Stringable`s) | ||
* @param stringLikes An array of `Stringable`s found in the tagged template | ||
@@ -113,5 +116,13 @@ * | ||
* await ctx.replyFmt(final); | ||
* | ||
* // Using regular function form | ||
* const cart = fmt([ | ||
* "Your shopping cart:\n", | ||
* ...items.map((item) => fmt`- ${bold(item.name)} (${item.price})\n`), | ||
* ]); | ||
* // Using result in editMessageText | ||
* await ctx.editMessageText(cart.text, { entities: cart.entities }); | ||
* ``` | ||
*/ | ||
declare const fmt: (rawStringParts: TemplateStringsArray | string[], ...stringLikes: Stringable[]) => FormattedString; | ||
declare const fmt: (rawStringParts: TemplateStringsArray | Stringable[], ...stringLikes: Stringable[]) => FormattedString; | ||
export { bold, code, fmt, FormattedString, italic, link, linkMessage, mentionUser, pre, spoiler, strikethrough, underline, }; |
@@ -145,3 +145,6 @@ "use strict"; | ||
* in further `fmt` tagged templates. | ||
* @param rawStringParts An array of `string` parts found in the tagged template | ||
* | ||
* Can also be called like regular function and passed an array of `Stringable`s. | ||
* | ||
* @param rawStringParts An array of `string` parts found in the tagged template (can also be `Stringable`s) | ||
* @param stringLikes An array of `Stringable`s found in the tagged template | ||
@@ -156,17 +159,27 @@ * | ||
* await ctx.replyFmt(final); | ||
* | ||
* // Using regular function form | ||
* const cart = fmt([ | ||
* "Your shopping cart:\n", | ||
* ...items.map((item) => fmt`- ${bold(item.name)} (${item.price})\n`), | ||
* ]); | ||
* // Using result in editMessageText | ||
* await ctx.editMessageText(cart.text, { entities: cart.entities }); | ||
* ``` | ||
*/ | ||
const fmt = (rawStringParts, ...stringLikes) => { | ||
let text = rawStringParts[0]; | ||
let text = ""; | ||
const entities = []; | ||
for (let i = 0; i < stringLikes.length; i++) { | ||
const stringLike = stringLikes[i]; | ||
if (stringLike instanceof FormattedString) { | ||
entities.push(...stringLike.entities.map((e) => ({ | ||
...e, | ||
offset: e.offset + text.length, | ||
}))); | ||
const length = Math.max(rawStringParts.length, stringLikes.length); | ||
for (let i = 0; i < length; i++) { | ||
for (const stringLike of [rawStringParts[i], stringLikes[i]]) { | ||
if (stringLike instanceof FormattedString) { | ||
entities.push(...stringLike.entities.map((e) => ({ | ||
...e, | ||
offset: e.offset + text.length, | ||
}))); | ||
} | ||
if (stringLike != null) | ||
text += stringLike.toString(); | ||
} | ||
text += stringLike.toString(); | ||
text += rawStringParts[i + 1]; | ||
} | ||
@@ -173,0 +186,0 @@ return new FormattedString(text, entities); |
{ | ||
"name": "@grammyjs/parse-mode", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "Plugin for hydrating ctx with familiar reply variants and for setting default parse_mode", | ||
@@ -5,0 +5,0 @@ "author": "KnightNiwrem", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25138
15
533