https://github.com/blackglory/extra-tags
🌲
https://github.com/blackglory/extra-tags
browser esm library nodejs npm-package typescript
Last synced: 5 months ago
JSON representation
🌲
- Host: GitHub
- URL: https://github.com/blackglory/extra-tags
- Owner: BlackGlory
- License: mit
- Created: 2021-07-10T10:43:02.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-07-29T04:53:23.000Z (12 months ago)
- Last Synced: 2025-08-09T05:57:45.570Z (11 months ago)
- Topics: browser, esm, library, nodejs, npm-package, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/extra-tags
- Size: 565 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# extra-tags
## Install
```sh
npm install --save extra-tags
# or
yarn add extra-tags
```
## API
### map
```ts
function map>(
fn: (value: T, index: number) => U
, strings: Strings
, ...values: T[]
): [strings: Strings, ...values: U[]]
function map(
fn: (value: T, index: number) => U
): >(
strings: Strings
, ...values: T[]
) => [strings: Strings, ...values: U[]]
```
### filter
```ts
function filter(
predicate: (value: T, index: number) => boolean
, strings: TemplateStringsArray
, ...values: T[]
): [strings: TemplateStringsArray, ...values: U[]]
function filter(
predicate: (value: T, index: number) => boolean
, strings: ReadonlyArray
, ...values: T[]
): [strings: ReadonlyArray, ...values: U[]]
function filter(
predicate: (value: T, index: number) => boolean
): >(
strings: Strings
, ...values: T[]
) => [
strings: Strings extends TemplateStringsArray
? TemplateStringsArray
: ReadonlyArray
, ...values: U[]
]
```
### array
```ts
function array(strings: TemplateStringsArray, ...values: T[]): Array
```
```ts
array`a${1}b${2}c`
// ['a', 1, 'b', 2, 'c']
```
### fromArray
```ts
function fromArray(arr: Array): [
strings: string[]
, ...values: T[]
]
```
```ts
fromArray(array`a${1}b${2}c`)
// [['a', 'b', 'c'], 1, 2]
```
### concat
```ts
function concat(strings: ReadonlyArray, ...values: unknown[]): string
```
It is equivalent to `Array.prototype.concat` for template arguments.
```ts
// It doesn't make sense to use it as a tag function,
// because it equivalent to `a${'b'}c${'d'}e`.
concat`a${'b'}c${'d'}e`
// 'abcde'
concat(strings, ...values)
// 'abcde'
```
### dedent
```ts
function dedent(strings: ReadonlyArray, ...values: unknown[]): string
```
```ts
dedent`
hello
world
`
// 'hello' + '\n'
// + 'world'
```
### oneline
```ts
function oneline(
separator: string
, strings: ReadonlyArray
, ...values: unknown[]
): string
function oneline(
separator: string
): (strings: ReadonlyArray, ...values: unknown[]) => string
function oneline(strings: ReadonlyArray, ...values: unknown[]): string
```
```ts
oneline(' ')`
hello
world
`
// 'hello world'
```
### indentMultilineValues
```ts
function indentMultilineValues>(
strings: Strings
, ...values: string[]
): [strings: Strings, ...values: string[]]
```
```ts
const [strings, ...values] = indentMultilineValues`
a
${'b\nc'}
d
`
// strings: [
// '\n'
// + ' '.repeat(2) + 'a' + '\n'
// , '\n'
// + ' '.repeat(2) + 'd' + '\n'
// ]
// values: [
// 'b' + '\n'
// + ' '.repeat(2) + 'c'
// ]
```
### javascript
```ts
type JavaScriptValue =
| string
| number
| boolean
| null
| bigint
| undefined
| ((args: any) => any)
| { [property: string]: JavaScriptValue }
| JavaScriptValue[]
function javascript(strings: ReadonlyArray, ...values: JavaScriptValue[]): string
```
```ts
javascript`
const text = ${'hello world'}
console.log(text)
`
// const text = "hello world"
// console.log(text)
```