Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/TS 496 Self assessment extraction word counts #1275

Merged
Merged
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
57 changes: 53 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint-ci": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --no-fix --ignore-path .gitignore"
},
"dependencies": {
"@jac-uk/jac-kit": "4.1.41",
"@jac-uk/jac-kit": "4.1.53",
"@ministryofjustice/frontend": "0.2.4",
"@sentry/vue": "^8.33.1",
"@vue/compat": "^3.3.4",
Expand Down
13 changes: 2 additions & 11 deletions src/components/Form/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script>
import { isValidNumberForRegion } from 'libphonenumber-js';
import { formatDate } from '@/helpers/date';
import { splitWords } from '@jac-uk/jac-kit/helpers/splitWords';

export default {
name: 'FormField',
Expand Down Expand Up @@ -79,17 +80,7 @@ export default {
words() {
const value = this.modelValue;
const result = value ? value : '';
return [].concat(...result
.split(/[^a-z'-]/i) //split into array at every occurance of a character which is NOT: a-z or ' or -
.filter(item => item != '') // remove any empty items from array
.filter(item => item != '\'') // remove any items which are just a apostrophe
.filter(item => item != '-') // remove any items which are just a hyphen
.map((item, i) => { // with the above array
if (i, item.replace(/[^-]/g, '').length >= 4) { // find any items containing more than or equal to 4 hyphens (4 allows for a trailing hyphen which is not counted in next set)
item = item.match(/((?:[^-]*?-){3}[^-]*?)-|([\S\s]+)/g); // if an 'offending' item occurs, group every 4 words, ignoring the hyphen between groups [ie. 'one-one-one-one-two-two-two-two' (eight words, seven hyphens) 'one-one-one-one-' 'two-two-two-two']
}
return item; // add array in position of word
})); // flatten array
return splitWords(result);
},
},
mounted: function () {
Expand Down
Loading