Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,35 @@
}
}
],
"extends": ["next/core-web-vitals", "airbnb-typescript"],
"extends": [
"next/core-web-vitals",
"airbnb-typescript"
],
"rules": {
"import/order": ["error", {
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"type"
],
"pathGroups": [
{
"pattern": "~core/**",
"group": "internal"
},
{
"pattern": "~utils/**",
"group": "internal"
}
],
"alphabetize": {
"order": "asc"
}
}],
"semi": ["error", "always"],
"object-curly-spacing": ["error", "always"],
"eol-last": ["error", "always"],
Expand Down
7,397 changes: 1,449 additions & 5,948 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
"lint": "next lint"
},
"dependencies": {
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0"
"next": "^12.3.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/jest": "29.0.0",
"@types/node": "18.7.2",
"@types/react": "18.0.17",
"@types/react-dom": "18.0.6",
"@typescript-eslint/eslint-plugin": "5.13.0",
"@typescript-eslint/parser": "5.0.0",
"eslint": "8.21.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-next": "12.2.5",
"jest": "29.0.2",
"ts-jest": "29.0.2",
"typescript": "4.7.4"
"@types/jest": "^29.4.0",
"@types/node": "^18.15.0",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"eslint": "^8.36.0",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-next": "^12.3.4",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
}
}
4 changes: 2 additions & 2 deletions src/core/formatter/formatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Formatter } from '@core/formatter/formatter';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { Formatter } from '~core/formatter/formatter';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';

describe('Formatter class: validation', () => {
test('Selection range should has \'from\' less than \'to\'', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/formatter/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { applyFormatToToken, isTokenFormattable } from '@core/formatter/utils/helpers/format';
import { isTokenSplittable, normalizeTokens, resolvePositionLocationInTokens, splitTokenByPosition } from '@core/formatter/utils/helpers/other';
import { first, last } from '@utils/helpers/array';
import { applyFormatToToken, isTokenFormattable } from '~core/formatter/utils/helpers/format';
import { isTokenSplittable, normalizeTokens, resolvePositionLocationInTokens, splitTokenByPosition } from '~core/formatter/utils/helpers/other';
import { first, last } from '~utils/helpers/array';

export class Formatter {
private constructor() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applyFormatToToken } from '@core/formatter/utils/helpers/format';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { applyFormatToToken } from '~core/formatter/utils/helpers/format';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'applyFormatToToken\' helper', () => {
test('Should add format to token if it does not contain it', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTokenFormattable } from '@core/formatter/utils/helpers/format';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { isTokenFormattable } from '~core/formatter/utils/helpers/format';
import { TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'isTokenFormattable\' helper', () => {
test('Should return true only for token that can be format', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTokenSplittable } from '@core/formatter/utils/helpers/other';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { isTokenSplittable } from '~core/formatter/utils/helpers/other';
import { TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'isTokenSplittable\' helper', () => {
test('Should return true only for token that value can be split', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { TOKEN_TYPE } from '~core/model/utils/constants';

export const isTokenSplittable = (token: Token): boolean => (
token.type === TOKEN_TYPE.TEXT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { filterEmpty } from '@core/formatter/utils/helpers/other/normalizeTokens/filterEmpty/filterEmpty';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { filterEmpty } from '~core/formatter/utils/helpers/other/normalizeTokens/filterEmpty/filterEmpty';
import { TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'filterEmpty\' helper', () => {
test('Should filter tokens with empty value', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { joinSimilar } from '@core/formatter/utils/helpers/other/normalizeTokens/joinSimilar/joinSimilar';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { joinSimilar } from '~core/formatter/utils/helpers/other/normalizeTokens/joinSimilar/joinSimilar';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'joinSimilar\' helper', () => {
test('Should join tokens only with same type (\'text\') and equal formats', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTokenFormattable } from '@core/formatter/utils/helpers/format';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { isTokenFormattable } from '~core/formatter/utils/helpers/format';
import { TOKEN_TYPE } from '~core/model/utils/constants';

export const joinSimilar = (tokens: Token[]): Token[] => (
tokens.reduce((acc, currentToken) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalizeTokens } from '@core/formatter/utils/helpers/other';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { normalizeTokens } from '~core/formatter/utils/helpers/other';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'normalizeTokens\' helper', () => {
test('Should filter empty and join similar tokens', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { joinSimilar } from '@core/formatter/utils/helpers/other/normalizeTokens/joinSimilar/joinSimilar';
import { filterEmpty } from '@core/formatter/utils/helpers/other/normalizeTokens/filterEmpty/filterEmpty';
import { filterEmpty } from '~core/formatter/utils/helpers/other/normalizeTokens/filterEmpty/filterEmpty';
import { joinSimilar } from '~core/formatter/utils/helpers/other/normalizeTokens/joinSimilar/joinSimilar';

export const normalizeTokens = (tokens: Token[]): Token[] => (
joinSimilar(filterEmpty(tokens))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolvePositionLocationInTokens } from '@core/formatter/utils/helpers/other';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { resolvePositionLocationInTokens } from '~core/formatter/utils/helpers/other';
import { TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'resolvePositionLocationInTokens\' helper', () => {
const firstValue = 'text1';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { splitTokenByPosition } from '@core/formatter/utils/helpers/other';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { splitTokenByPosition } from '~core/formatter/utils/helpers/other';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';

describe('\'splitTokenByPosition\' helper', () => {
test('Should split token value by position (with saving other properties)', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneToken } from '@core/model/utils/helpers/other';
import { cloneToken } from '~core/model/utils/helpers/other';

export const splitTokenByPosition = <T extends Token>(token: T, position: Position): [Token, Token] => {
const beforePositionToken = { ...cloneToken(token), value: token.value.slice(0, position) };
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/model.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';
import { Model } from './model';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';

describe('Model class: creating tokens', () => {
test('Should create text token with/without format', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cloneToken } from '@core/model/utils/helpers/other';
import { TOKEN_FORMAT, TOKEN_TYPE } from '@core/model/utils/constants';
import { TOKEN_FORMAT, TOKEN_TYPE } from '~core/model/utils/constants';
import { cloneToken } from '~core/model/utils/helpers/other';

describe('\'cloneToken\' helper', () => {
test('Should deep clone token', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isTokenFormattable } from '@core/formatter/utils/helpers/format';
import { isTokenFormattable } from '~core/formatter/utils/helpers/format';

export const cloneToken = <T extends Token>(token: T): T => {
return isTokenFormattable(token) ? { ...token, formats: new Set(token.formats) } : { ...token };
Expand Down
4 changes: 2 additions & 2 deletions src/core/parser/handlers/hashtag/hashtag.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Model } from '@core/model/model';
import { Parser } from '@core/parser/parser';
import { Model } from '~core/model/model';
import { Parser } from '~core/parser/parser';
import { parseHashTag } from './hashtag';

describe('Hashtag parsing: consuming symbols', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/core/parser/handlers/hashtag/hashtag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Parser } from '@core/parser/parser';
import { Model } from '@core/model/model';
import { isHashTagName } from '@core/parser/utils/helpers/hashtag';
import { last } from '@utils/helpers/array';
import { UNICODE_CODES } from '@core/parser/utils/constants';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { Model } from '~core/model/model';
import { TOKEN_TYPE } from '~core/model/utils/constants';
import type { Parser } from '~core/parser/parser';
import { UNICODE_CODES } from '~core/parser/utils/constants';
import { isHashTagName } from '~core/parser/utils/helpers/hashtag';
import { last } from '~utils/helpers/array';

const isHashTagBound = (parser: Parser): boolean => {
// ✅ important:
Expand Down
4 changes: 2 additions & 2 deletions src/core/parser/handlers/newline/newline.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Model } from '@core/model/model';
import { Parser } from '@core/parser/parser';
import { Model } from '~core/model/model';
import { Parser } from '~core/parser/parser';
import { parseNewLine } from './newline';

describe('Newline parsing: consuming symbols', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/core/parser/handlers/newline/newline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Parser } from '@core/parser/parser';
import { Model } from '@core/model/model';
import { UNICODE_CODES } from '@core/parser/utils/constants';
import { Model } from '~core/model/model';
import type { Parser } from '~core/parser/parser';
import { UNICODE_CODES } from '~core/parser/utils/constants';

const consumeNewLine = (parser: Parser): boolean => {
// ✅ important:
Expand Down
2 changes: 1 addition & 1 deletion src/core/parser/handlers/text/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parser } from '@core/parser/parser';
import { Parser } from '~core/parser/parser';
import { parseText } from './text';

describe('Text parsing: consuming symbols', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core/parser/handlers/text/text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Parser } from '@core/parser/parser';
import type { Parser } from '~core/parser/parser';

export const parseText = (parser: Parser): boolean => {
parser.consumeText();
Expand Down
4 changes: 2 additions & 2 deletions src/core/parser/parser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Model } from '@core/model/model';
import { Parser } from '@core/parser/parser';
import { Model } from '~core/model/model';
import { Parser } from '~core/parser/parser';

describe('Parser class: constructor', () => {
test('Parser with initial tokens should not be in consuming status if last token not text', () => {
Expand Down
16 changes: 8 additions & 8 deletions src/core/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { parseHashTag } from '@core/parser/handlers/hashtag/hashtag';
import { parseNewLine } from '@core/parser/handlers/newline/newline';
import { parseText } from '@core/parser/handlers/text/text';
import { Model } from '@core/model/model';
import { resolveNextCodePointUnitCount, resolvePrevCodePointUnitCount } from '@core/parser/utils/helpers/codePoint';
import { isDelimiter } from '@core/parser/utils/helpers/other';
import { last } from '@utils/helpers/array';
import { TOKEN_TYPE } from '@core/model/utils/constants';
import { Model } from '~core/model/model';
import { TOKEN_TYPE } from '~core/model/utils/constants';
import { parseHashTag } from '~core/parser/handlers/hashtag/hashtag';
import { parseNewLine } from '~core/parser/handlers/newline/newline';
import { parseText } from '~core/parser/handlers/text/text';
import { resolveNextCodePointUnitCount, resolvePrevCodePointUnitCount } from '~core/parser/utils/helpers/codePoint';
import { isDelimiter } from '~core/parser/utils/helpers/other';
import { last } from '~utils/helpers/array';

// eslint-disable-next-line
interface IParser {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UTF16_UTIL } from '@core/parser/utils/constants';
import { UTF16_UTIL } from '~core/parser/utils/constants';
import { resolveNextCodePointUnitCount } from './resolveNextCodePointUnitCount';

describe('\'resolveNextCodePointUnitCount\' helper: unit count', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UTF16_UTIL } from '@core/parser/utils/constants';
import { UTF16_UTIL } from '~core/parser/utils/constants';

export const resolveNextCodePointUnitCount = (nextCodePoint: CodePoint): number => {
const isNextCodePointIsSurrogatePair = nextCodePoint > UTF16_UTIL.UNIT_MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UTF16_UTIL } from '@core/parser/utils/constants';
import { UTF16_UTIL } from '~core/parser/utils/constants';
import { resolvePrevCodePointUnitCount } from './resolvePrevCodePointUnitCount';

describe('\'resolvePrevCodePointUnitCount\' helper: unit count', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UTF16_UTIL } from '@core/parser/utils/constants';
import { UTF16_UTIL } from '~core/parser/utils/constants';

export const resolvePrevCodePointUnitCount = (prevCodePoint: CodePoint): number => {
const isPrevCodePointIsLowUnitOfSurrogatePair = prevCodePoint >= UTF16_UTIL.LOW_SURROGATE_MIN_VALUE && prevCodePoint <= UTF16_UTIL.LOW_SURROGATE_MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isLetter, isNumber } from '../../other';
import { UNICODE_CODES } from '../../../constants';
import { isLetter, isNumber } from '../../other';

export const isHashTagName = (codePoint: CodePoint): boolean => (
isLetter(codePoint) || isNumber(codePoint) || codePoint === UNICODE_CODES.LOWLINE
Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"incremental": true,
"baseUrl": ".",
"paths": {
"@core/formatter/*": ["src/core/formatter/*"],
"@core/model/*": ["src/core/model/*"],
"@core/parser/*": ["src/core/parser/*"],
"@utils/*": ["src/utils/*"]
"~core/formatter/*": ["src/core/formatter/*"],
"~core/model/*": ["src/core/model/*"],
"~core/parser/*": ["src/core/parser/*"],
"~utils/*": ["src/utils/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
Expand Down