Skip to content

Commit

Permalink
chore: Update infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Apr 1, 2024
1 parent 61754b6 commit ae0e655
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 260 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
/lib
/src/playground.ts
4 changes: 0 additions & 4 deletions .eslintrc

This file was deleted.

11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
"extends": ["@diplodoc/eslint-config"],
"root": true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
"env": {
"node": true
}
}
19 changes: 0 additions & 19 deletions .github/workflows/ci.yaml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
verify_files:
name: Verify Files
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18.x'
cache: 'npm'
- name: Install Packages
run: npm ci
- name: Lint Files
run: npm run lint
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
push:
branches: [master]

name: release

permissions:
contents: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- run: npm ci
shell: bash
- uses: codex-team/action-nodejs-package-info@v1
id: package
- uses: GoogleCloudPlatform/release-please-action@v3
id: release
with:
token: ${{secrets.YC_UI_BOT_GITHUB_TOKEN}}
release-type: node
package-name: ${{steps.package.outputs.name}}
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"perf","section":"Performance Improvements","hidden":false}]'
bump-minor-pre-major: true
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.ROBOT_DATAUI_NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
shell: bash
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: ['**']

jobs:
test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [18.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
os: ${{ matrix.os }}
cache: 'npm'
- name: Install packages for project
run: npm ci
- run: npm run build
- name: Install packages for tests
run: |
cd tests
npm ci
- name: Run tests
run: |
cd tests
npm run test
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('@yandex-cloud/prettier-config');
module.exports = require('@diplodoc/prettier-config')
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"build:dev": "npm run build:dev:clean && npm run build:dev:code",
"build:dev:code": "node scripts/development.js",
"build:dev:clean": "rm -rf dist",
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm run build"
},
"author": {
Expand All @@ -37,19 +39,17 @@
},
"license": "MIT",
"devDependencies": {
"@diplodoc/eslint-config": "^2.0.0",
"@diplodoc/prettier-config": "^2.0.0",
"@diplodoc/tsconfig": "^1.0.2",
"@es-exec/api": "0.0.5",
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
"@tsconfig/node14": "^1.0.3",
"@types/jest": "^27.5.2",
"@types/node": "^17.0.35",
"@yandex-cloud/eslint-config": "^1.0.1",
"@yandex-cloud/prettier-config": "^1.0.0",
"esbuild": "^0.17.18",
"esbuild-jest": "^0.5.0",
"esbuild-node-externals": "^1.7.0",
"eslint": "^8.16.0",
"jest": "^28.1.0",
"prettier": "^2.6.2",
"typescript": "^5.0.4"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export {
SENTENCE_END_MARKERS,
QUOTATION_GENERIC_MARKERS,
QUOTATION_CLOSE_MARKERS,
BRACKETS_CLOSE_MARKERS,
SENTENCE_END_MARKERS,
QUOTATION_GENERIC_MARKERS,
QUOTATION_CLOSE_MARKERS,
BRACKETS_CLOSE_MARKERS,
} from './markers';

export {WINDOW_WIDTH} from './parameters';
Expand Down
8 changes: 4 additions & 4 deletions src/constants/markers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const QUOTATION_CLOSE_MARKERS = '»”’';
const BRACKETS_CLOSE_MARKERS = '\\)\\]\\}>';

export {
SENTENCE_END_MARKERS,
QUOTATION_GENERIC_MARKERS,
QUOTATION_CLOSE_MARKERS,
BRACKETS_CLOSE_MARKERS,
SENTENCE_END_MARKERS,
QUOTATION_GENERIC_MARKERS,
QUOTATION_CLOSE_MARKERS,
BRACKETS_CLOSE_MARKERS,
};
105 changes: 52 additions & 53 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/* eslint-disable security/detect-non-literal-regexp, security/detect-unsafe-regex */
import {compose, anyPass, zipWith, call} from 'ramda';
import {anyPass, call, compose, zipWith} from 'ramda';

import {sentences, fstChars, lstChars} from './parsers';
import {fstChars, lstChars, sentences} from './parsers';
import {
spaceBothSides,
rightLacksSpacePrefix,
rightStartsWithLowercase,
rightDelimiterPrefix,
rightQuotationGenericPrefix,
rightQuotationClosePrefix,
rightBracketsClosePrefix,
rightOnlySpaces,
leftInitials,
leftAbbreviation,
pairAbbreviation,
leftPairsTailAbbreviation,
rightStartsWithHardbreak,
rightStartsNewlineUppercased,
leftEndsWithHardbreak,
leftAbbreviation,
leftEndsWithHardbreak,
leftInitials,
leftPairsTailAbbreviation,
pairAbbreviation,
rightBracketsClosePrefix,
rightDelimiterPrefix,
rightLacksSpacePrefix,
rightOnlySpaces,
rightQuotationClosePrefix,
rightQuotationGenericPrefix,
rightStartsNewlineUppercased,
rightStartsWithHardbreak,
rightStartsWithLowercase,
spaceBothSides,
} from './rules';

// sides preprocessing before evaluation
Expand All @@ -27,55 +26,55 @@ const sidesPreprocessors = [leftPreprocessor, rightPreprocessor];

// conditions to join upon
const joinCondition = anyPass([
spaceBothSides,
rightLacksSpacePrefix,
rightStartsWithLowercase,
rightDelimiterPrefix,
rightQuotationGenericPrefix,
rightQuotationClosePrefix,
rightBracketsClosePrefix,
rightOnlySpaces,
leftInitials,
leftAbbreviation,
pairAbbreviation,
leftPairsTailAbbreviation,
spaceBothSides,
rightLacksSpacePrefix,
rightStartsWithLowercase,
rightDelimiterPrefix,
rightQuotationGenericPrefix,
rightQuotationClosePrefix,
rightBracketsClosePrefix,
rightOnlySpaces,
leftInitials,
leftAbbreviation,
pairAbbreviation,
leftPairsTailAbbreviation,
]);

const breakCondition = anyPass([
leftEndsWithHardbreak,
rightStartsWithHardbreak,
rightStartsNewlineUppercased,
leftEndsWithHardbreak,
rightStartsWithHardbreak,
rightStartsNewlineUppercased,
]);

const join = compose(joinCondition, zipWith<any, any, any>(call, sidesPreprocessors));
const breaks = compose(breakCondition, zipWith<any, any, any>(call, sidesPreprocessors));

// sentences processing
export function sentenize(text: string): string[] {
const parts = text.split(/((?:\n\s*){2,})/);
const parsed: string[] = [];
const parts = text.split(/((?:\n\s*){2,})/);
const parsed: string[] = [];

for (const part of parts) {
const chunks = sentences(part);
for (const part of parts) {
const chunks = sentences(part);

let left: string | null = null;
for (const right of chunks) {
if (!left) {
left = right;
continue;
}
let left: string | null = null;
for (const right of chunks) {
if (!left) {
left = right;
continue;
}

if (!breaks([left, right]) && join([left, right])) {
left += right;
} else {
parsed.push(left);
if (!breaks([left, right]) && join([left, right])) {
left += right;
} else {
parsed.push(left);

left = right;
}
}

if (left) parsed.push(left);
left = right;
}
}

return parsed;
if (left) parsed.push(left);
}

return parsed;
}
Loading

0 comments on commit ae0e655

Please sign in to comment.