{"id":5404,"date":"2023-01-05T12:36:38","date_gmt":"2023-01-05T04:36:38","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5404"},"modified":"2023-01-05T12:36:38","modified_gmt":"2023-01-05T04:36:38","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e5%ad%97%e4%b8%b2%e7%9a%84%e5%b8%95%e6%96%af%e5%8d%a1%e5%ad%97%e7%ac%a6%e4%b8%b2pascalcase%e6%aa%a2%e6%b8%ac%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e5%ad%97%e4%b8%b2%e7%9a%84%e5%b8%95%e6%96%af%e5%8d%a1%e5%ad%97%e7%ac%a6%e4%b8%b2pascalcase%e6%aa%a2%e6%b8%ac%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u5b57\u4e32\u7684\u5e15\u65af\u5361\u5b57\u7b26\u4e32(PascalCase)\u6aa2\u6e2c\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u5b57\u4e32, \u5e15\u65af\u5361\u5b57\u7b26\u4e32, isPascalCase\"><\/p>\n<h1>TypeScript \u5b57\u4e32\u7684\u6c42\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32(isPascalCase)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u985e\u578b\u7cfb\u7d71\u548c\u975c\u614b\u6aa2\u67e5\u529f\u80fd\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u53ef\u9760\u7684\u7a0b\u5f0f\u78bc\u3002\u5728 TypeScript \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 isPascalCase() \u51fd\u5f0f\u4f86\u6aa2\u67e5\u4e00\u500b\u5b57\u4e32\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5e15\u65af\u5361\u5b57\u7b26\u4e32\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u5b57\u4e32\u683c\u5f0f\uff0c\u5b83\u7684\u6bcf\u500b\u55ae\u8a5e\u7684\u9996\u5b57\u6bcd\u90fd\u662f\u5927\u5beb\u7684\uff0c\u800c\u5176\u4ed6\u5b57\u6bcd\u90fd\u662f\u5c0f\u5beb\u7684\u3002\u4f8b\u5982\uff0c&#8221;HelloWorld&#8221; \u5c31\u662f\u4e00\u500b\u5e15\u65af\u5361\u5b57\u7b26\u4e32\uff0c\u800c &#8220;helloWorld&#8221; \u5247\u4e0d\u662f\u3002<\/p>\n<p>isPascalCase() \u51fd\u5f0f\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u4e00\u500b\u5b57\u4e32\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32\u3002\u5b83\u63a5\u53d7\u4e00\u500b\u5b57\u4e32\u53c3\u6578\uff0c\u4e26\u8fd4\u56de\u4e00\u500b\u5e03\u6797\u503c\uff0c\u8868\u793a\u8a72\u5b57\u4e32\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32\u3002<\/p>\n<pre class=\"brush: typescript\">\nfunction isPascalCase(str: string): boolean {\n  \/\/ \u6aa2\u67e5\u5b57\u4e32\u662f\u5426\u70ba\u7a7a\n  if (str.length === 0) {\n    return false;\n  }\n\n  \/\/ \u6aa2\u67e5\u5b57\u4e32\u7684\u6bcf\u500b\u5b57\u5143\n  for (let i = 0; i < str.length; i++) {\n    const char = str.charAt(i);\n\n    \/\/ \u6aa2\u67e5\u9996\u5b57\u6bcd\u662f\u5426\u70ba\u5927\u5beb\n    if (i === 0 &#038;&#038; !char.match(\/[A-Z]\/)) {\n      return false;\n    }\n\n    \/\/ \u6aa2\u67e5\u5176\u4ed6\u5b57\u6bcd\u662f\u5426\u70ba\u5c0f\u5beb\n    if (i > 0 && !char.match(\/[a-z]\/)) {\n      return false;\n    }\n  }\n\n  return true;\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u662f isPascalCase() \u51fd\u5f0f\u7684\u5be6\u73fe\uff0c\u5b83\u63a5\u53d7\u4e00\u500b\u5b57\u4e32\u53c3\u6578\uff0c\u4e26\u6aa2\u67e5\u8a72\u5b57\u4e32\u7684\u6bcf\u500b\u5b57\u5143\uff0c\u5982\u679c\u5b57\u4e32\u7684\u6bcf\u500b\u5b57\u5143\u90fd\u7b26\u5408\u5e15\u65af\u5361\u5b57\u7b26\u4e32\u7684\u898f\u5247\uff0c\u5247\u8fd4\u56de true\uff0c\u5426\u5247\u8fd4\u56de false\u3002<\/p>\n<p>\u4f7f\u7528 isPascalCase() \u51fd\u5f0f\u53ef\u4ee5\u8f15\u9b06\u5730\u6aa2\u67e5\u4e00\u500b\u5b57\u4e32\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32\uff0c\u9019\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u53ef\u4ee5\u5e6b\u52a9\u4ed6\u5011\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u53ef\u9760\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):\u5e15\u65af\u5361\u5b57\u7b26\u4e32(PascalCase)\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\uff0c\u5b83\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u7ba1\u7406\u548c\u7dad\u8b77\u4ee3\u78bc\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528TypeScript\u4f86\u6aa2\u6e2c\u5b57\u7b26\u4e32\u662f\u5426\u70ba\u5e15\u65af\u5361\u5b57\u7b26\u4e32(PascalCase)\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5404","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1pa","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5404"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5404\/revisions"}],"predecessor-version":[{"id":5405,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5404\/revisions\/5405"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}