mirror of https://github.com/sveltejs/svelte
parent
7c85039471
commit
e86fb16402
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @template T
|
||||
* @overload
|
||||
* @param {T[][]} nodes
|
||||
* @param {T[]} [target]
|
||||
* @returns {T[]}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @overload
|
||||
* @param {T[]} nodes
|
||||
* @param {T[]} [target]
|
||||
* @returns {T[]}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {any[]} nodes
|
||||
* @param {any[]} [target]
|
||||
* @returns {any[]}
|
||||
*/
|
||||
export function flatten(nodes, target = []) {
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const node = nodes[i];
|
||||
if (Array.isArray(node)) {
|
||||
flatten(node, target);
|
||||
} else {
|
||||
target.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
export function flatten<T>(nodes: T[][], target?: T[]): T[];
|
||||
export function flatten<T>(nodes: T[], target?: T[]): T[];
|
||||
export function flatten(nodes: any[], target: any[] = []): any[] {
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const node = nodes[i];
|
||||
if (Array.isArray(node)) {
|
||||
flatten(node, target);
|
||||
} else {
|
||||
target.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
@ -1,7 +1,12 @@
|
||||
// Adapted from https://github.com/acornjs/acorn/blob/6584815dca7440e00de841d1dad152302fdd7ca5/src/tokenize.js
|
||||
// Reproduced under MIT License https://github.com/acornjs/acorn/blob/master/LICENSE
|
||||
|
||||
export default function full_char_code_at(str: string, i: number): number {
|
||||
/**
|
||||
* @param {string} str
|
||||
* @param {number} i
|
||||
* @returns {number}
|
||||
*/
|
||||
export default function full_char_code_at(str, i) {
|
||||
const code = str.charCodeAt(i);
|
||||
if (code <= 0xd7ff || code >= 0xe000) return code;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/** ----------------------------------------------------------------------
|
||||
This file is automatically generated by `scripts/globals-extractor.mjs`.
|
||||
Generated At: 2022-09-03T15:22:37.415Z
|
||||
Generated At: 2023-05-11T15:31:28.406Z
|
||||
---------------------------------------------------------------------- */
|
||||
|
||||
export default new Set([
|
||||
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @template {{ next?: T; prev?: T }} T
|
||||
* @param {T} next
|
||||
* @param {T} prev
|
||||
*/
|
||||
export function link(next, prev) {
|
||||
prev.next = next;
|
||||
if (next) next.prev = prev;
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
export function link<T extends { next?: T; prev?: T }>(next: T, prev: T) {
|
||||
prev.next = next;
|
||||
if (next) next.prev = prev;
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
export default function list(items: string[], conjunction = 'or') {
|
||||
/**
|
||||
* @param {string[]} items
|
||||
* @param {string} [conjunction]
|
||||
*/
|
||||
export default function list(items, conjunction = 'or') {
|
||||
if (items.length === 1) return items[0];
|
||||
return `${items.slice(0, -1).join(', ')} ${conjunction} ${items[items.length - 1]}`;
|
||||
}
|
||||
@ -1,9 +1,15 @@
|
||||
import { regex_starts_with_whitespaces, regex_ends_with_whitespaces } from './patterns';
|
||||
import { regex_starts_with_whitespaces, regex_ends_with_whitespaces } from './patterns.js';
|
||||
|
||||
export function trim_start(str: string) {
|
||||
/**
|
||||
* @param {string} str
|
||||
*/
|
||||
export function trim_start(str) {
|
||||
return str.replace(regex_starts_with_whitespaces, '');
|
||||
}
|
||||
|
||||
export function trim_end(str: string) {
|
||||
/**
|
||||
* @param {string} str
|
||||
*/
|
||||
export function trim_end(str) {
|
||||
return str.replace(regex_ends_with_whitespaces, '');
|
||||
}
|
||||
Loading…
Reference in new issue