0.0.0 • Published 9 years ago

classname v0.0.0

Weekly downloads
6,420
License
ISC
Repository
github
Last release
9 years ago

classname v.0.0.1

Simple tool to build (and apply) classes. This is very much inspired by Jed Watson's classnames, but with added functionality and slight differences in interface.

Install

Npm: npm install classname

Or just load classname.js in your browser, and call it directly.

Documentation

classname(1, 'one', false, 'two'); // '1 one two'

classname({
    one: true,
    two: false,
    three: true
});
// 'one three'

classname(['one', 'two'], {one: false, three: true});
// 'two three'

Objects always overwrite other types of parameters

classname({one: false}, ['one', 'two']);
// 'two'

classname handles more than string, numbers, arrays, and objects though. You can give it elements, nodelists, or jQuery elements too.

classname(document.querySelectorAll('.foo'), 'bar');
// 'foo bar' (assuming that the found elements do not have other class names as well)

classname can also set the class to the element for you. Use .setTo():

var el = document.getElementById('foo');

classname.setTo(el)('one', 'two');

el.className; // 'one two'
datocms-plugin-datocms-plugin-link-tree-field-editorlemoui-vuespankpay-componentsdatocms-plugin-auto-iddatocms-plugin-auto-uidkudi-component-libreact_date_pickerwt-window111text-dumi-wx02@everything-registry/sub-chunk-1332ydlmwebydl-mobilexa-inputweb-toolkittest-nhatmi-111v-schema-form-elementv-schema-form-nextui-lemontaro-msttcloudsolomon-class-prefix@one_zhd/do-ui@mindk/react-material-form-generator@osui/theme-providerxjt-new@vmo-fed/react-tooltip@wjrtest/bc-bl-drawer@wjrtest/bc-bl-drawer2@weahead/datocms-plugin-translated-stringseld-ui-reacteditorcore@riil-frontend/component-no-data-page@spotinst/spinnaker-deck@sgg10/components-reactaisuda-quickappamphora-sitesform-assembly@amperio/datocms-plugin-auto-uuid@alanquigley/react-scripts@zalastax/nolb-clasapathiadesigngithub-explorer@chainge/pluginchoose-modal-listhon-component-mvvmkugichkas-uilib@careteam/dates-timelinekanban-pannelreact-admin-copy-clipboad-fieldreact-jsplumbreact-mslide@dulemon/react-tooltipreact-mchartreact-mobile-sliderreact-mhocpicidae-theme-haierdecentraland-adikone-componentsnemean-class-prefixreact-tooltip2react-utils-componentsr-date-pickerreact-fields-keeperdatocms-plugin-wiris-quizzes-studiodatocms-plugin-preview-links-spotlytedatocms-plugin-preview-localesdatocms-plugin-random-id-generatordatocms-plugin-readonly-fieldsdatocms-plugin-repeaterfielddatocms-plugin-saleor-productdatocms-plugin-tinymcedatocms-plugin-todo-listdatocms-plugin-sequential-id-generatordatocms-plugin-shopify-product-iddatocms-plugin-shopify-product-jsondatocms-plugin-sidebar-link-buttonsdatocms-plugin-simple-chartdatocms-plugin-spotlyte-preview-linkdatocms-plugin-spotlyte-static-page-preview-linkdatocms-plugin-stripe-pricedatocms-plugin-desmos-plugindatocms-plugin-full-preview-linksdatocms-plugin-gatsby-clouddatocms-plugin-auto-uuiddatocms-plugin-chartdatocms-plugin-ckeditor-mathtypedatocms-plugin-commercelayerdatocms-plugin-commercetools-productdatocms-plugin-conditional-fields-extendeddatocms-plugin-gatsby-previewdatocms-plugin-link-tree-field-editordatocms-plugin-modular-contentdatocms-plugin-open-assetdatocms-plugin-optionsdatocms-plugin-preview-linkdatocms-plugin-preview-links@firesoon/bl-drawer@firesoon/business-componentniubility-ship@icedesign/asset-management-scaffold
0.0.0

9 years ago