Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
64963937
Commit
64963937
authored
Aug 20, 2020
by
Kev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create convertUnicodeToAscii text_utility method
parent
d795ab07
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
2 deletions
+97
-2
app/assets/javascripts/lib/utils/text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+70
-0
app/assets/javascripts/projects/project_new.js
app/assets/javascripts/projects/project_new.js
+7
-2
spec/frontend/lib/utils/text_utility_spec.js
spec/frontend/lib/utils/text_utility_spec.js
+20
-0
No files found.
app/assets/javascripts/lib/utils/text_utility.js
View file @
64963937
...
@@ -275,6 +275,76 @@ export const convertToSentenceCase = string => {
...
@@ -275,6 +275,76 @@ export const convertToSentenceCase = string => {
*/
*/
export
const
convertToTitleCase
=
string
=>
string
.
replace
(
/
\b[
a-z
]
/g
,
s
=>
s
.
toUpperCase
());
export
const
convertToTitleCase
=
string
=>
string
.
replace
(
/
\b[
a-z
]
/g
,
s
=>
s
.
toUpperCase
());
const
unicodeConversion
=
[
[
/
[
ÀÁÂÃÅĀĂĄ
]
/g
,
'
A
'
],
[
/
[
Æ
]
/g
,
'
AE
'
],
[
/
[
ÇĆĈĊČ
]
/g
,
'
C
'
],
[
/
[
ÈÉÊËĒĔĖĘĚ
]
/g
,
'
E
'
],
[
/
[
ÌÍÎÏĨĪĬĮİ
]
/g
,
'
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
[
/
[
ţťŧ
]
/g
,
'
t
'
],
[
/
[
Ŵ
]
/g
,
'
W
'
],
[
/
[
ŵ
]
/g
,
'
w
'
],
[
/
[
ŹŻŽ
]
/g
,
'
Z
'
],
[
/
[
źżž
]
/g
,
'
z
'
],
[
/ö/g
,
'
oe
'
],
[
/ü/g
,
'
ue
'
],
[
/ä/g
,
'
ae
'
],
[
/Ö/g
,
'
Oe
'
],
[
/Ü/g
,
'
Ue
'
],
[
/Ä/g
,
'
Ae
'
],
];
/**
* Converts each non-ascii character in a string to
* it's ascii equivalent (if defined).
*
* e.g. "Dĭd söméònê äšk fœŕ Ůnĭċődę?" => "Did someone aesk foer Unicode?"
*
* @param {String} string
* @returns {String}
*/
export
const
convertUnicodeToAscii
=
string
=>
{
for
(
let
[
regex
,
replacer
]
of
unicodeConversion
)
{
string
=
string
.
replace
(
regex
,
replacer
);
}
return
string
;
};
/**
/**
* Splits camelCase or PascalCase words
* Splits camelCase or PascalCase words
* e.g. HelloWorld => Hello World
* e.g. HelloWorld => Hello World
...
...
app/assets/javascripts/projects/project_new.js
View file @
64963937
import
$
from
'
jquery
'
;
import
$
from
'
jquery
'
;
import
DEFAULT_PROJECT_TEMPLATES
from
'
ee_else_ce/projects/default_project_templates
'
;
import
DEFAULT_PROJECT_TEMPLATES
from
'
ee_else_ce/projects/default_project_templates
'
;
import
{
addSelectOnFocusBehaviour
}
from
'
../lib/utils/common_utils
'
;
import
{
addSelectOnFocusBehaviour
}
from
'
../lib/utils/common_utils
'
;
import
{
convertToTitleCase
,
humanize
,
slugify
}
from
'
../lib/utils/text_utility
'
;
import
{
convertToTitleCase
,
humanize
,
slugify
,
convertUnicodeToAscii
,
}
from
'
../lib/utils/text_utility
'
;
let
hasUserDefinedProjectPath
=
false
;
let
hasUserDefinedProjectPath
=
false
;
let
hasUserDefinedProjectName
=
false
;
let
hasUserDefinedProjectName
=
false
;
const
onProjectNameChange
=
(
$projectNameInput
,
$projectPathInput
)
=>
{
const
onProjectNameChange
=
(
$projectNameInput
,
$projectPathInput
)
=>
{
const
slug
=
slugify
(
$projectNameInput
.
val
(
));
const
slug
=
slugify
(
convertUnicodeToAscii
(
$projectNameInput
.
val
()
));
$projectPathInput
.
val
(
slug
);
$projectPathInput
.
val
(
slug
);
};
};
...
...
spec/frontend/lib/utils/text_utility_spec.js
View file @
64963937
...
@@ -205,6 +205,26 @@ describe('text_utility', () => {
...
@@ -205,6 +205,26 @@ describe('text_utility', () => {
});
});
});
});
describe
(
'
convertUnicodeToAscii
'
,
()
=>
{
it
(
'
does nothing on an empty string
'
,
()
=>
{
expect
(
textUtils
.
convertUnicodeToAscii
(
''
)).
toBe
(
''
);
});
it
(
'
does nothing on an already ascii string
'
,
()
=>
{
expect
(
textUtils
.
convertUnicodeToAscii
(
'
The quick brown fox jumps over the lazy dog.
'
)).
toBe
(
'
The quick brown fox jumps over the lazy dog.
'
,
);
});
it
(
'
replaces Unicode characters
'
,
()
=>
{
expect
(
textUtils
.
convertUnicodeToAscii
(
'
Dĭd söméònê äšk fœŕ Ůnĭċődę?
'
)).
toBe
(
'
Did someone aesk foer Unicode?
'
,
);
expect
(
textUtils
.
convertUnicodeToAscii
(
"
Jürgen's Projekt
"
)).
toBe
(
"
Juergen's Projekt
"
);
});
});
describe
(
'
splitCamelCase
'
,
()
=>
{
describe
(
'
splitCamelCase
'
,
()
=>
{
it
(
'
separates a PascalCase word to two
'
,
()
=>
{
it
(
'
separates a PascalCase word to two
'
,
()
=>
{
expect
(
textUtils
.
splitCamelCase
(
'
HelloWorld
'
)).
toBe
(
'
Hello World
'
);
expect
(
textUtils
.
splitCamelCase
(
'
HelloWorld
'
)).
toBe
(
'
Hello World
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment