2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-08 17:22:26 +03:00

feat: typescript support (#185)

* feat: initial typescript support

* feat: typescript support

* feat(plugin-helper): move files to typescript

* chore: update lock files

* feat: preset types

* fix: build

* fix: benchmark

* fix: remove pnpm cache

* fix: bench action

* fix: pnpm recursive install

* fix: nx cache

* fix: lock file

* fix: workflows

* fix: lerna support in pnpm

* fix: pnpm workspace

* fix: remove unused files

* fix: pnpm lock file

* fix: update lerna for support pnpm

* fix: lerna bootstrap

* fix: rollup build

* fix: update nx

* fix: build

* fix: add nx dep target

* fix: remove nx cache

* fix: workflow run on push only for master

* fix: test workflow run on push only for master

* fix: remove parallel for gen types

* fix: benchmark

* fix: benchmark imports

* fix: pnpm

* fix: types errors and pnpm

* fix: types

* fix: types

* refactor: parser

* fix(parser): tests

* fix: preset tests

* fix: react types

* fix: react type declarations

* fix: pnpm lock file

* fix: react preset types

* fix: lock file

* fix: vue2 types

* feat: dev container support

* fix: types

* fix: types

* refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts

* refactor: types

* fix: types

* fix: rename gen-types to types

* fix: nx build order

* fix: nx reset

* fix: define nx deps explicit

* fix: build

* fix: nx

* fix: nx order build

* fix: nx deps

* fix: bbob cli tests

* fix: tests

* fix: cli tests and import

* fix: test cover

* fix: cli cover
This commit is contained in:
Nikolay Kost
2024-04-23 21:11:14 +02:00
committed by GitHub
parent 05246b2aea
commit 8797f7f363
149 changed files with 6102 additions and 3670 deletions
+121
View File
@@ -0,0 +1,121 @@
import {
QUOTEMARK,
BACKSLASH,
} from '@bbob/plugin-helper';
export type CharGrabberOptions = {
onSkip?: () => void
}
export class CharGrabber {
private s: string;
private c: { len: number; pos: number };
private o: CharGrabberOptions;
constructor(source: string, options: CharGrabberOptions = {}) {
this.s = source
this.c = {
pos: 0,
len: source.length,
};
this.o = options
}
skip(num = 1, silent?: boolean) {
this.c.pos += num;
if (this.o && this.o.onSkip && !silent) {
this.o.onSkip();
}
}
hasNext() {
return this.c.len > this.c.pos
}
getCurr() {
return this.s[this.c.pos]
}
getRest() {
return this.s.substring(this.c.pos)
}
getNext() {
const nextPos = this.c.pos + 1;
return nextPos <= (this.s.length - 1) ? this.s[nextPos] : null;
}
getPrev() {
const prevPos = this.c.pos - 1;
return typeof this.s[prevPos] !== 'undefined' ? this.s[prevPos] : null;
}
isLast() {
return this.c.pos === this.c.len
}
includes(val: string) {
return this.s.indexOf(val, this.c.pos) >= 0
}
grabWhile(condition: (curr: string) => boolean, silent?: boolean) {
let start = 0;
if (this.hasNext()) {
start = this.c.pos;
while (this.hasNext() && condition(this.getCurr())) {
this.skip(1, silent);
}
}
return this.s.substring(start, this.c.pos);
}
grabN(num: number = 0) {
return this.s.substring(this.c.pos, this.c.pos + num)
}
/**
* Grabs rest of string until it find a char
*/
substrUntilChar(char: string) {
const { pos } = this.c;
const idx = this.s.indexOf(char, pos);
return idx >= 0 ? this.s.substring(pos, idx) : '';
}
}
/**
* Creates a grabber wrapper for source string, that helps to iterate over string char by char
*/
export const createCharGrabber = (source: string, options?: CharGrabberOptions) => new CharGrabber(source, options);
/**
* Trims string from start and end by char
* @example
* trimChar('*hello*', '*') ==> 'hello'
*/
export const trimChar = (str: string, charToRemove: string) => {
while (str.charAt(0) === charToRemove) {
// eslint-disable-next-line no-param-reassign
str = str.substring(1);
}
while (str.charAt(str.length - 1) === charToRemove) {
// eslint-disable-next-line no-param-reassign
str = str.substring(0, str.length - 1);
}
return str;
};
/**
* Unquotes \" to "
*/
export const unquote = (str: string) => str.replace(BACKSLASH + QUOTEMARK, QUOTEMARK);