{"id":14457,"date":"2024-03-08T07:36:03","date_gmt":"2024-03-08T04:36:03","guid":{"rendered":"https:\/\/elzero.org\/?p=14457"},"modified":"2024-03-08T07:38:18","modified_gmt":"2024-03-08T04:38:18","slug":"creadte-slug-from-string-with-javascript","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/creadte-slug-from-string-with-javascript\/","title":{"rendered":"\u0625\u0646\u0634\u0627\u0621 Slug \u0644\u0623\u064a String"},"content":{"rendered":"<div class=\"text\">\r\n\u0627\u0644 Slug \u0647\u0648 \u0639\u0628\u0627\u0631\u0629 \u0639\u0646 \u0627\u0644 String \u0628\u0639\u062f \u062a\u062d\u0648\u064a\u0644\u0647 \u0625\u0644\u0649 \u062d\u0631\u0648\u0641 \u0635\u063a\u064a\u0631\u0629 \u0648\u0625\u0633\u062a\u0628\u062f\u0627\u0644 \u0627\u0644\u0645\u0633\u0627\u0641\u0627\u062a \u0628\u0639\u0644\u0627\u0645\u0629 \u0627\u0644 \u201c-\u201d \u0648\u0625\u0632\u0627\u0644\u0629 \u0643\u0644 \u0645\u0627 \u0647\u0648 \u063a\u064a\u0631 \u0627\u0644\u0623\u0631\u0642\u0627\u0645 \u0648\u0627\u0644\u062d\u0631\u0648\u0641 \u0648\u064a\u0645\u0643\u0646\u0643 \u0645\u0634\u0627\u0647\u062f\u0629 \u0627\u0644\u0645\u062b\u0627\u0644 \u0642\u0628\u0644 \u0639\u0645\u0644 \u0627\u0644 Code\r\n<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\n\/\/ String Before\r\n\" Hello@ I -- Love Elzero Web School   \"\r\n\r\n\/\/ String After \"Slug\"\r\n\"hello-i-love-elzero-web-school\"\r\n<\/script>\r\n\r\n<div class=\"text\">\r\n\u0647\u0646\u0627 \u0633\u062a\u062c\u062f \u0646\u0633\u062e\u0629 \u0628\u0633\u064a\u0637\u0629 \u0644\u0639\u0645\u0644 \u0627\u0644\u0645\u0637\u0644\u0648\u0628 \u0645\u0628\u0627\u0634\u0631\u0629 \u0648\u0644\u0643\u0646 \u0628\u0639\u062f\u0647\u0627 \u0633\u062a\u062c\u062f Function \u0645\u0641\u0635\u0644\u0629 \u0628\u0627\u0644\u0634\u0631\u062d\r\n<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction createSlugFrom(myString) {\r\n  return myString\r\n    .toLowerCase()\r\n    .replace(\/[^a-z0-9]+\/g, \"-\")\r\n    .replace(\/^-+|-+$\/g, \"\");\r\n}\r\n\r\nconsole.log(createSlugFrom(\" Hello@ I -- Love Elzero Web School   \")); \/\/ hello-i-love-elzero-web-school\r\n<\/script>\r\n\r\n<div class=\"text\">\r\n\u062a\u0627\u0628\u0639 \u0645\u0639\u064a \u0643\u0644 \u0633\u0637\u0631 \u0641\u064a \u0627\u0644 Function \u0644\u062a\u0639\u0631\u0641 \u0643\u064a\u0641 \u062a\u0639\u0645\u0644 \u0627\u0644 Function \u0648\u0644\u062a\u0631\u0649 \u0627\u0644\u0646\u062a\u064a\u062c\u0629 \u062a\u062d\u062a \u0643\u0644 \u0633\u0637\u0631\r\n<\/div>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\nfunction createSlugFrom(myString) {\r\n  \/\/ Remove Whitespace From Start And End of String\r\n  result = myString.trim();\r\n  \/\/ Result = Hello@ I -- Love Elzero Web School\r\n\r\n  \/\/ Make Characters Lowercase\r\n  result = result.toLowerCase();\r\n  \/\/ Result = hello@ i -- love elzero web school\r\n\r\n  \/\/ Remove All Invalid Characters.\r\n  \/\/ Anything Except Letters, Numbers, Spaces, and Hyphens\r\n  result = result.replace(\/[^a-z0-9 -]\/g, \"\");\r\n  \/\/ Result = hello i -- love elzero web school\r\n\r\n  \/\/ Replace Whitespace With \"-\"\r\n  result = result.replace(\/\\s+\/g, \"-\");\r\n  \/\/ Result = hello-i----love-elzero-web-school\r\n\r\n  \/\/ If There's Consecutive Hyphens Merge Them\r\n  result = result.replace(\/-+\/g, \"-\");\r\n  \/\/ Result = hello-i-love-elzero-web-school\r\n\r\n  return result;\r\n}\r\n\r\nconsole.log(createSlugFrom(\" Hello@ I -- Love Elzero Web School   \")); \/\/ hello-i-love-elzero-web-school\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0637\u0631\u064a\u0642\u0629 \u0625\u0646\u0634\u0627\u0621 Slug \u0644\u0623\u064a String <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[525],"tags":[1446,457,331,1444,1445],"class_list":["post-14457","post","type-post","status-publish","format-standard","hentry","category-javascript-tutorials","tag-create-js","tag-function","tag-javascript","tag-slug","tag-slugify"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14457"}],"version-history":[{"count":4,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14457\/revisions"}],"predecessor-version":[{"id":14462,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14457\/revisions\/14462"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}