state()
更新日: 2018-09-04
state()
// 使い方
chance.state()
chance.state({ full: true })
chance.state({ territories: true })
chance.state({ armed_forces: true })
chance.state({ us_states_and_dc: false })
chance.state({ country: 'us' })アメリカの州名をランダムで返します。
chance.state();
=> 'AK'デフォルトでは、2文字の省略形の州名を返します。
fullを指定すると、省略していない州名を返します。
chance.state({ full: true });
=> 'Florida'territoriesを指定すると、アメリカ合衆国の海外領土をランダム対象に追加します。
追加される地域: American Samoa、Federated States of Micronesia、Guam、Marshall Islands、 Northern Mariana Islands、Puerto Rico、Virgin Islands, U.S.
chance.state({ territories: true, full: true })
=> 'Guam'armed_forcesを指定すると、アメリカ軍の管轄区域を追加します。
chance.state({ armed_forces: true, full: true })
=> 'Armed Forces Pacific'全ての州、領土、軍の管轄区域を含める場合は、以下のように指定します。
chance.state({ armed_forces: true, territories: true })
=> 'NY'領土または、軍の管轄区域のみに制限する場合は、us_states_and_dcを指定します。
chance.state({ territories: true, us_states_and_dc: false })
=> 'PR'countryを指定すると、国を指定することができます。 countryがusではない場合、固有のオプションは無視されます。
chance.state({ country: 'it', full: true })
=> 'Toscana'現在、指定可能な国はus(アメリカ)、it(イタリア)、uk(イギリス)です。
デモ
ボタンを押すと、アメリカの州名、領土、軍管轄区域をランダムに表示します。
結果:
JavaScript
var button = document.getElementById('get-result');
button.addEventListener('click', function() {
var chance = new Chance();
document.getElementById('result').innerHTML = chance.state({ armed_forces: true, territories: true, full: true });
}, false);
HTML
<button id="get-result">結果表示</button>
<div>
<span>結果:</span>
<span id="result"></span>
</div>© 2015 Victor Quinn Released under the MIT license
このコンテンツはVictor Quinn(victorquinn)によるChanceドキュメントを翻訳/改変したものです。