From 485cf25315ee6dc67f958d0ad541bb44184df71f Mon Sep 17 00:00:00 2001 From: Diego Montenegro Date: Tue, 29 Jul 2025 17:13:27 -0500 Subject: [PATCH 1/4] creat folder normalize and file normalize.md with all information about it --- .../strings/terms/normalize/normalize.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 content/javascript/concepts/strings/terms/normalize/normalize.md diff --git a/content/javascript/concepts/strings/terms/normalize/normalize.md b/content/javascript/concepts/strings/terms/normalize/normalize.md new file mode 100644 index 00000000000..ed9864c4cd9 --- /dev/null +++ b/content/javascript/concepts/strings/terms/normalize/normalize.md @@ -0,0 +1,58 @@ +--- +Title: '.normalize()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed +Description: 'It is used in the context of text strings and is used to convert a string into a standard Unicode normalization.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) +Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! + - 'Data Analysis' + - 'Machine Learning' +Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! + - 'String' + - 'Methods' +CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'introduction-to-javascript' + - 'paths/front-end-engineer-career-path' +--- + +**Normalize** It is used in the context of text strings and is used to convert a string into a standard Unicode normalization. + +## Syntax + +```js +string.normalize('NFC', word1); +``` + +## Example + +Normalized 'café' to 'cafe' + +```js +const word1 = "café"; + +const word1Normalized = word1.normalize('NFC'); + +console.log(word1Normalized); +// Output: cafe +``` + +## Codebyte Example (if applicable) + +We can currently support: + +- Python +- JavaScript +- Java +- C# +- Ruby +- PHP + +The following is runnable and demonstrates the .normalize() method + +```codebyte/javascript +const name1 = "Mañana"; +const name2 = "Man\u0303ana"; + +const name1Normalized = name1.normalize('NFC'); +const name2Normalized = name2.normalize('NFC'); + +console.log(name1Normalized); // Manana +console.log(name2Normalized); // Manana +``` \ No newline at end of file From 3974c066bf04955a7f05f92912fc16bb6a9fa3a9 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 1 Aug 2025 16:24:51 +0530 Subject: [PATCH 2/4] minor content fixes --- .../strings/terms/normalize/normalize.md | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/content/javascript/concepts/strings/terms/normalize/normalize.md b/content/javascript/concepts/strings/terms/normalize/normalize.md index ed9864c4cd9..b05609a2603 100644 --- a/content/javascript/concepts/strings/terms/normalize/normalize.md +++ b/content/javascript/concepts/strings/terms/normalize/normalize.md @@ -1,58 +1,65 @@ --- -Title: '.normalize()' # Required; the file name should be the same as the title, but lowercase, with dashes instead of spaces, and all punctuation removed -Description: 'It is used in the context of text strings and is used to convert a string into a standard Unicode normalization.' # Required; ideally under 150 characters and starts with a present-tense verb (used in search engine results and content previews) -Subjects: # Please only use Subjects in the subjects.md file (https://github.com/Codecademy/docs/blob/main/documentation/subjects.md). If that list feels insufficient, feel free to create a new Subject and add it to subjects.md in your PR! - - 'Data Analysis' - - 'Machine Learning' -Tags: # Please only use Tags in the tags.md file (https://github.com/Codecademy/docs/blob/main/documentation/tags.md). If that list feels insufficient, feel free to create a new Tag and add it to tags.md in your PR! - - 'String' +Title: '.normalize()' +Description: 'Returns the Unicode Normalization Form of a string.' +Subjects: + - 'Code Foundations' + - 'Computer Science' +Tags: + - 'JavaScript' - 'Methods' -CatalogContent: # Please use course/path landing page slugs, rather than linking to individual content items. If listing multiple items, please put the most relevant one first + - 'String' + - 'Unicode' +CatalogContent: - 'introduction-to-javascript' - 'paths/front-end-engineer-career-path' --- -**Normalize** It is used in the context of text strings and is used to convert a string into a standard Unicode normalization. +The **`.normalize()`** method returns the Unicode Normalization Form of a string. This is especially useful when comparing strings that may look identical but are composed of different Unicode code points. ## Syntax -```js -string.normalize('NFC', word1); +```pseudo +string.normalize([form]) ``` -## Example +**Parameters:** -Normalized 'café' to 'cafe' +- `form` (optional): A string specifying the Unicode normalization form. Valid values are: + - `'NFC'` (default): Canonical Composition + - `'NFD'`: Canonical Decomposition + - `'NFKC'`: Compatibility Composition + - `'NFKD'`: Compatibility Decomposition -```js -const word1 = "café"; +**Return value:** + +A new string in the specified normalization form. + +## Example: Comparing Unicode Representations -const word1Normalized = word1.normalize('NFC'); +In this example, two visually identical strings have different Unicode encodings, and `.normalize()` is used to make them comparable. -console.log(word1Normalized); -// Output: cafe +```js +const word1 = '\u00e9'; // é as single character +const word2 = '\u0065\u0301'; // e + ́ (combining acute) + +console.log(word1 === word2); +console.log(word1.normalize() === word2.normalize()); ``` -## Codebyte Example (if applicable) +The output of this code is: -We can currently support: +```shell +false +true +``` -- Python -- JavaScript -- Java -- C# -- Ruby -- PHP +## Codebyte Example: Stripping Accents Using Normalize + Regex -The following is runnable and demonstrates the .normalize() method +In this example, `.normalize()` is combined with a regular expression to strip accents by removing Unicode diacritical marks: ```codebyte/javascript -const name1 = "Mañana"; -const name2 = "Man\u0303ana"; +const word = 'café'; +const stripped = word.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); -const name1Normalized = name1.normalize('NFC'); -const name2Normalized = name2.normalize('NFC'); - -console.log(name1Normalized); // Manana -console.log(name2Normalized); // Manana -``` \ No newline at end of file +console.log(stripped); +``` From 5bc2a528288bf4142eecca670243bcc9451e82b3 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 1 Aug 2025 16:25:48 +0530 Subject: [PATCH 3/4] Update normalize.md --- .../javascript/concepts/strings/terms/normalize/normalize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/javascript/concepts/strings/terms/normalize/normalize.md b/content/javascript/concepts/strings/terms/normalize/normalize.md index b05609a2603..1043f931436 100644 --- a/content/javascript/concepts/strings/terms/normalize/normalize.md +++ b/content/javascript/concepts/strings/terms/normalize/normalize.md @@ -14,7 +14,7 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -The **`.normalize()`** method returns the Unicode Normalization Form of a string. This is especially useful when comparing strings that may look identical but are composed of different Unicode code points. +The **`.normalize()`** method returns the Unicode Normalization Form of a [string](https://www.codecademy.com/resources/docs/javascript/strings). This is especially useful when comparing strings that may look identical but are composed of different Unicode code points. ## Syntax From cbe7e17e27631cb65d7f58ab68158745fd15b09c Mon Sep 17 00:00:00 2001 From: Sriparno Roy Date: Thu, 7 Aug 2025 11:01:25 +0530 Subject: [PATCH 4/4] Minor changes --- .../strings/terms/normalize/normalize.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/content/javascript/concepts/strings/terms/normalize/normalize.md b/content/javascript/concepts/strings/terms/normalize/normalize.md index 1043f931436..280bfc95105 100644 --- a/content/javascript/concepts/strings/terms/normalize/normalize.md +++ b/content/javascript/concepts/strings/terms/normalize/normalize.md @@ -14,7 +14,7 @@ CatalogContent: - 'paths/front-end-engineer-career-path' --- -The **`.normalize()`** method returns the Unicode Normalization Form of a [string](https://www.codecademy.com/resources/docs/javascript/strings). This is especially useful when comparing strings that may look identical but are composed of different Unicode code points. +The **`.normalize()`** method in JavaScript returns the Unicode Normalization Form of a string. This is especially useful when comparing strings that may look identical but are composed of different Unicode code points. ## Syntax @@ -24,8 +24,8 @@ string.normalize([form]) **Parameters:** -- `form` (optional): A string specifying the Unicode normalization form. Valid values are: - - `'NFC'` (default): Canonical Composition +- `form` (Optional): A string specifying the Unicode normalization form. Valid values are: + - `'NFC'` (Default): Canonical Composition - `'NFD'`: Canonical Decomposition - `'NFKC'`: Compatibility Composition - `'NFKD'`: Compatibility Decomposition @@ -36,11 +36,11 @@ A new string in the specified normalization form. ## Example: Comparing Unicode Representations -In this example, two visually identical strings have different Unicode encodings, and `.normalize()` is used to make them comparable. +In this example, two visually identical strings have different Unicode encodings, and `.normalize()` is used to make them comparable: ```js -const word1 = '\u00e9'; // é as single character -const word2 = '\u0065\u0301'; // e + ́ (combining acute) +const word1 = '\u00e9'; // é as single character +const word2 = '\u0065\u0301'; // e + ́ (combining acute) console.log(word1 === word2); console.log(word1.normalize() === word2.normalize()); @@ -55,11 +55,11 @@ true ## Codebyte Example: Stripping Accents Using Normalize + Regex -In this example, `.normalize()` is combined with a regular expression to strip accents by removing Unicode diacritical marks: +In this codebyte example, `.normalize()` is combined with a regular expression to strip accents by removing Unicode diacritical marks: ```codebyte/javascript const word = 'café'; const stripped = word.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); -console.log(stripped); +console.log(stripped); ```