Skip to content

Commit

Permalink
Sort and add g-zip size
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic16x committed Dec 4, 2024
1 parent 47b03bd commit f154c31
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"eslint-plugin-storybook": "^0.11.1",
"file-loader": "^6.2.0",
"globals": "^15.12.0",
"gzip-size": "^7.0.0",
"html-webpack-plugin": "^5.6.3",
"jest": "^29.7.0",
"jsdom": "^25.0.1",
Expand Down
27 changes: 15 additions & 12 deletions src/services/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IAlphabets } from 'reducers'

import {
convertCases,
deduplicate,
filterLatin,
filterNiqqud,
getCaseTips,
Expand Down Expand Up @@ -235,20 +236,22 @@ class DictionaryClass {

switch (lang) {
case 'isv':
splittedField = this
.splittedMap['isv-src']
.get(id)
.map((word) => this.searchPrepare(lang, word))
.filter((item, i, ar) => ar.indexOf(item) === i)

splittedField = deduplicate(
this
.splittedMap['isv-src']
.get(id)
.map((word) => this.searchPrepare(lang, word))
)

break
case 'isv-src':
splittedField = this
.splitWords(fromField)
.concat(getWordForms(item))
.map((word) => this.searchPrepare('isv-src', getLatin(word, '2')))
.filter((item, i, ar) => ar.indexOf(item) === i)

splittedField = deduplicate(
this
.splitWords(fromField)
.concat(getWordForms(item))
.map((word) => this.searchPrepare('isv-src', getLatin(word, '2')))
)

break
default:
splittedField = this.splitWords(fromField).map((word) => this.searchPrepare(lang, word))
Expand Down
8 changes: 7 additions & 1 deletion src/services/generateDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Dictionary, loadTablesData } from 'services'

import { getColumnName, transposeMatrix } from 'utils'

import { gzipSizeSync } from 'gzip-size'


loadTablesData.then(({ data, columns }) => {
Dictionary.init(data)
Expand All @@ -24,7 +26,7 @@ loadTablesData.then(({ data, columns }) => {
}
})

const basicData = transposeMatrix(basicDataTransposed)
const basicData = transposeMatrix(basicDataTransposed).sort((a, b) => a[1].localeCompare(b[1]))

const searchIndexBasic = [
'isv-src',
Expand All @@ -49,6 +51,10 @@ loadTablesData.then(({ data, columns }) => {
fs.writeFileSync('./static/data/basic.json', jsonDataStr)
fs.writeFileSync('./static/data/translateStatistic.json', translateStatisticStr)

const sizeMB = gzipSizeSync(jsonDataStr) / 1000000
// eslint-disable-next-line no-console
console.info(`basic.json g-zip size: ${sizeMB.toFixed(2)} MB`)

addLangs.forEach((lang) => {
const langDataTransposed = [
columns.find(([fieldName]) => fieldName === lang),
Expand Down
1 change: 1 addition & 0 deletions src/utils/deduplicate/deduplicate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const deduplicate = (arr) => Array.from(new Set(arr))
1 change: 1 addition & 0 deletions src/utils/deduplicate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './deduplicate'
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './bcp47'
export * from './convertCases'
export * from './createTaggedTemplate'
export * from './deduplicate'
export * from './filterLatin'
export * from './filterNiqqud'
export * from './getAllDataFromResults'
Expand Down

0 comments on commit f154c31

Please sign in to comment.