読者です 読者をやめる 読者になる 読者になる

webhack / 猫とウェブ技術が好き

javascriptやcssやHTML5とかサーバーサイドの技術やプロジェクトマネジメントとかウェブに関するマーケティングとかWEBを取り巻く全般を好きに書くブログ

ウェブフォームにダミーの値を入れる"jQuery-Faker"

jQuery-Fakerは開発中のフォームにダミー値を自動入力するjQueryプラグインです。

jQuery-faker by All-Go-Rhytm

使い方はこれだけです。

$( "#myform" ).fakify();

例えばcustomerの属性address_1に番地を入れる場合には"address.streetAddress"を指定します。

$("#myform").fakify({
  "except": ["customer[mname]","city"], // keeps mname and city from auto generating
  "customer[address_1]": "address.streetAddress", // maps address_1 field to street_address
  "customer[nick_name]": ["Chaure", "Dalley", "Daure", "Bhyagute", "Gole"] // adds custom datatype along with the data
  "customer[country]": ["Nepal", "China"] // restricts country data type to "Nepal" and "China" only
});

標準でよく使われるデータセットが最初から準備されています。

$.fakifyDictionary = {
    name: {
        firstName: ['Aarav', 'Ajita', 'Amit', 'Amita', 'Amrit', 'Arijit', 'Ashmi', 'Asmita', 'Bibek', 'Bijay', 'Bikash', 'Bina', 'Bishal', 'Bishnu', 'Buddha', 'Deepika', 'Dipendra', 'Gagan', 'Ganesh', 'Khem', 'Krishna', 'Laxmi', 'Manisha', 'Nabin', 'Nikita', 'Niraj', 'Nischal', 'Padam', 'Pooja', 'Prabin', 'Prakash', 'Prashant', 'Prem', 'Purna', 'Rajendra', 'Rajina', 'Raju', 'Rakesh', 'Ranjan', 'Ratna', 'Sagar', 'Sandeep', 'Sanjay', 'Santosh', 'Sarita', 'Shilpa', 'Shirisha', 'Shristi', 'Siddhartha', 'Subash', 'Sumeet', 'Sunita', 'Suraj', 'Susan', 'Sushant'],
        middleName: ['Sharma', 'Lal', 'Raj', 'Prasad', 'Dip', 'Kumar', 'Bhatta'],
        lastName: ['Adhikari', 'Aryal', 'Baral', 'Basnet', 'Bastola', 'Basynat', 'Bhandari', 'Bhattarai', 'Chettri', 'Devkota', 'Dhakal', 'Dongol', 'Ghale', 'Gurung', 'Gyawali', 'Hamal', 'Jung', 'KC', 'Kafle', 'Karki', 'Khadka', 'Koirala', 'Lama', 'Limbu', 'Magar', 'Maharjan', 'Niroula', 'Pandey', 'Pradhan', 'Rana', 'Raut', 'Sai', 'Shai', 'Shakya', 'Sherpa', 'Shrestha', 'Subedi', 'Tamang', 'Thapa']
    },
    address: {
        country: ['Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica (the territory South of 60 deg S)', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Bouvet Island (Bouvetoya)', 'Brazil', 'British Indian Ocean Territory (Chagos Archipelago)', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote d\'Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Faroe Islands', 'Falkland Islands (Malvinas)', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard Island and McDonald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Democratic People\'s Republic of Korea', 'Republic of Korea', 'Kuwait', 'Kyrgyz Republic', 'Lao People\'s Democratic Republic', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macao', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands Antilles', 'Netherlands', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Palestinian Territory', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn Islands', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Barthelemy', 'Saint Helena', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre and Miquelon', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard & Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States of America', 'United States Minor Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands', 'Britain', 'Virgin Islands', 'U.S.', 'Wallis and Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe'],
        state: ['Baglung', 'Banke', 'Bara', 'Bardiya', 'Bhaktapur', 'Bhojupu', 'Chitwan', 'Dailekh', 'Dang', 'Dhading', 'Dhankuta', 'Dhanusa', 'Dolakha', 'Dolpha', 'Gorkha', 'Gulmi', 'Humla', 'Ilam', 'Jajarkot', 'Jhapa', 'Jumla', 'Kabhrepalanchok', 'Kalikot', 'Kapilvastu', 'Kaski', 'Kathmandu', 'Lalitpur', 'Lamjung', 'Manang', 'Mohottari', 'Morang', 'Mugu', 'Mustang', 'Myagdi', 'Nawalparasi', 'Nuwakot', 'Palpa', 'Parbat', 'Parsa', 'Ramechhap', 'Rauswa', 'Rautahat', 'Rolpa', 'Rupandehi', 'Sankhuwasabha', 'Sarlahi', 'Sindhuli', 'Sindhupalchok', 'Sunsari', 'Surket', 'Syangja', 'Tanahu', 'Terhathum'],
        streetAddress: ['20341 Whitworth Institute 405 Whitworth Seattle WA 98052',
            'CHRIS NISWANDEE SMALLSYS INC 795 E DRAGRAM TUCSON AZ 85705 USA',
            'MARY ROE MEGASYSTEMS INC 799 E DRAGRAM SUITE 5A TUCSON AZ 85705 USA',
            'JANE ROE 200 E MAIN ST PHOENIX AZ 85123 USA',
            'JOHN SMITH 300 BOYLSTON AVE E SEATTLE WA 98102 USA'],
        stateAbbr: ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT'],
        city: ['Bhaktapur', 'Biratnagar', 'Birendranagar', 'Birgunj', 'Butwal', 'Damak', 'Dharan', 'Gaur', 'Gorkha', 'Hetauda', 'Itahari', 'Janakpur', 'Kathmandu', 'Lahan', 'Nepalgunj', 'Pokhara']
    },
    company: {
        name: ['Advanced Business Analysis', 'Advocate Services', 'African Internet Solutions.',
            'Bennie\'s Fishery', 'Bent Steel and Smelter', 'Best Friends Grooming Service',
            'Canadafab Steel', 'Can Do Coffee Distributors', 'Cat\'s Eye Technologies'],
        website: ['google.com', 'wikipedia.org', 'amazon.com', 'taobao.com', 'linkedin.com', 'tumblr.com',
            'pinterest.com', 'aliexpress.com', 'stackoverflow.com'],
        title: ['Your Brain on Drugs', 'A Separate Peace', 'Death by Dessert', 'The Chicago Manual of Style'],
        department: ['RoR', 'JAVA', 'PHP', 'Front End', 'UI/UX', 'Finance', 'HR']
    },
    personal: {
        academic: ['MBA', 'BBA', 'SLC', 'BE', 'BA', 'CA', 'BBS', 'ME']
    },
    domainName: ['gmail.com', 'yahoo.com', 'hotmail.com'],
    business: {
        creditCardNumbers: ['378282246310005', '371449635398431', '378734493671000', '5610591081018250',
            '30569309025904', '38520000023237', '6011111111111117', '6011000990139424', '3530111333300000',
            '3566002020360505', '5555555555554444', '5105105105105100', '4111111111111111']
    },
    notFound: ['Artificial intelligence is no match for natural stupidity.',
        'The last thing I want to do is insult you. But it IS on the list.',
        'I don\'t have a solution, but I do admire the problem.',
        'Letting the cat out of the bag is a whole lot easier than putting it back in.',
        'If at first you don\'t succeed, redefine success.']
};

フォームのテストで毎回ダミーで値を入れるの地味に手間だと思います。jQuery-Fakerを使うと開発が少しだけスムーズになりそうですね。