An open API service indexing awesome lists of open source software.

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

🌲

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)
```