@puregram/markup
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -26,6 +26,7 @@ import { Hooks } from 'puregram/hooks'; | ||
} | ||
type Rest = (StringLike | MarkupRepresentative)[]; | ||
interface MarkupElement { | ||
(text: string): MarkupRepresentative; | ||
(markup: MarkupRepresentative): MarkupRepresentative; | ||
(strings: TemplateStringsArray, ...rest: (StringLike | MarkupRepresentative)[]): MarkupRepresentative; | ||
(strings: TemplateStringsArray, ...rest: Rest): MarkupRepresentative; | ||
} | ||
@@ -115,3 +116,3 @@ interface MarkupRequiredElement<Fields extends string[]> { | ||
*/ | ||
export declare function format(strings: TemplateStringsArray, ...rest: (StringLike | MarkupRepresentative)[]): Formatted; | ||
export declare function format(strings: TemplateStringsArray, ...rest: Rest): Formatted; | ||
/** | ||
@@ -137,4 +138,4 @@ * The same as `format`, but this one strips all the leading spaces, not just the first group of spaces. | ||
*/ | ||
export declare function formatDedent(strings: TemplateStringsArray, ...rest: (StringLike | MarkupRepresentative)[]): Formatted; | ||
export declare function formatDedent(strings: TemplateStringsArray, ...rest: Rest): Formatted; | ||
export declare const hooks: (() => Partial<Hooks>); | ||
export {}; |
@@ -17,10 +17,8 @@ "use strict"; | ||
} | ||
const constructMarkup = (type, strings, ...rest) => { | ||
let text = ''; | ||
let offset = 0; | ||
function process(parts, ...rest) { | ||
let result = parts[0]; | ||
let offset = result.length; | ||
const entities = []; | ||
text += strings[0]; | ||
offset += text.length; | ||
for (let i = 0; i < rest.length; i++) { | ||
const frame = strings[i + 1]; | ||
const frame = parts[i + 1]; | ||
const arg = rest[i]; | ||
@@ -31,3 +29,5 @@ if (arg instanceof MarkupRepresentative) { | ||
} | ||
text += arg.text + frame; | ||
const addition = arg.text + frame; | ||
result += addition; | ||
offset += addition.length; | ||
entities.push(...arg.entities); | ||
@@ -37,6 +37,10 @@ } | ||
const addition = arg + frame; | ||
text += addition; | ||
result += addition; | ||
offset += addition.length; | ||
} | ||
} | ||
return { text: result, entities }; | ||
} | ||
const constructMarkup = (type, strings, ...rest) => { | ||
const { text, entities } = process(strings, ...rest); | ||
return new MarkupRepresentative({ | ||
@@ -165,28 +169,2 @@ text, | ||
exports.pre = buildWithField('pre', 'language'); | ||
function process(parts, ...rest) { | ||
let result = ''; | ||
let offset = 0; | ||
result += parts[0]; | ||
offset += result.length; | ||
const entities = []; | ||
for (let i = 0; i < rest.length; i++) { | ||
const frame = parts[i + 1]; | ||
const arg = rest[i]; | ||
if (arg instanceof MarkupRepresentative) { | ||
for (const entity of arg.entities) { | ||
entity.offset += offset; | ||
} | ||
const addition = arg.text + frame; | ||
result += addition; | ||
offset += addition.length; | ||
entities.push(...arg.entities); | ||
} | ||
else { | ||
const addition = arg + frame; | ||
result += addition; | ||
offset += addition.length; | ||
} | ||
} | ||
return new format_1.Formatted(result, entities.map(e => new puregram_1.MessageEntity(e))); | ||
} | ||
/** | ||
@@ -223,3 +201,4 @@ * Formats provided text using **entities**, not **formatting mode**. Also supports multiline text. | ||
} | ||
return process(parts, ...rest); | ||
const { text, entities } = process(parts, ...rest); | ||
return new format_1.Formatted(text, entities.map(e => new puregram_1.MessageEntity(e))); | ||
} | ||
@@ -254,5 +233,7 @@ exports.format = format; | ||
} | ||
return process(parts, ...rest); | ||
const { text, entities } = process(parts, ...rest); | ||
return new format_1.Formatted(text, entities.map(e => new puregram_1.MessageEntity(e))); | ||
} | ||
exports.formatDedent = formatDedent; | ||
// TODO: simplify...? | ||
const hooks = () => ({ | ||
@@ -259,0 +240,0 @@ onBeforeRequest: [ |
{ | ||
"name": "@puregram/markup", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "simple yet powerful markup system for puregram", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -88,2 +88,29 @@ <div align='center'> | ||
### `format(strings: TemplateStringsArray, ...rest: Rest)` | ||
formats the template and strips first pack of spaces from all lines *(`stripIndent`-like)* | ||
```js | ||
format` | ||
hello! | ||
those two spaces at the start will be stripped | ||
but those additional two spaces wont | ||
` | ||
``` | ||
### `formatDedent(strings: TemplateStringsArray, ...rest: Rest)` | ||
this one acts like `format` except it... ugh just roll the ~~credits~~ code example | ||
```js | ||
format` | ||
hello! | ||
those two spaces at the start will be stripped | ||
those additional two will also be stripped | ||
and those additional 18 spaces too! | ||
` | ||
``` | ||
*(`stripIndents`-like)* | ||
### `bold(text: string)` | ||
@@ -90,0 +117,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19637
224
0
454