1.0.0 • Published 14 days ago

@f1stnpm2/tempore-nesciunt-esse v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
14 days ago

@f1stnpm2/tempore-nesciunt-esse

NPM

NPM version Bundlephobia minified + gzip build codecov NPM downloads

Parses CSS inline style to JavaScript object (camelCased):

StyleToJS(string)

Example

import parse from '@f1stnpm2/tempore-nesciunt-esse';

parse('background-color: #BADA55;');

Output:

{ "backgroundColor": "#BADA55" }

Replit | JSFiddle | Examples

Install

NPM:

npm install @f1stnpm2/tempore-nesciunt-esse --save

Yarn:

yarn add @f1stnpm2/tempore-nesciunt-esse

CDN:

<script src="https://unpkg.com/@f1stnpm2/tempore-nesciunt-esse@latest/umd/@f1stnpm2/tempore-nesciunt-esse.min.js"></script>
<script>
  window.StyleToJS(/* string */);
</script>

Usage

Import

Import with ES Modules:

import parse from '@f1stnpm2/tempore-nesciunt-esse';

Require with CommonJS:

const parse = require('@f1stnpm2/tempore-nesciunt-esse');

Parse style

Parse single declaration:

parse('line-height: 42');

Output:

{ "lineHeight": "42" }

Notice that the CSS property is camelCased.

Parse multiple declarations:

parse(`
  border-color: #ACE;
  z-index: 1337;
`);

Output:

{
  "borderColor": "#ACE",
  "zIndex": "1337"
}

Vendor prefix

Parse vendor prefix:

parse(`
  -webkit-transition: all 4s ease;
  -moz-transition: all 4s ease;
  -ms-transition: all 4s ease;
  -o-transition: all 4s ease;
  -khtml-transition: all 4s ease;
`);

Output:

{
  "webkitTransition": "all 4s ease",
  "mozTransition": "all 4s ease",
  "msTransition": "all 4s ease",
  "oTransition": "all 4s ease",
  "khtmlTransition": "all 4s ease"
}

Custom property

Parse custom property:

parse('--custom-property: #f00');

Output:

{ "--custom-property": "#f00" }

Unknown declaration

This library does not validate declarations, so unknown declarations can be parsed:

parse('the-answer: 42;');

Output:

{ "theAnswer": "42" }

Invalid declaration

Declarations with missing value are removed:

parse(`
  margin-top: ;
  margin-right: 1em;
`);

Output:

{ "marginRight": "1em" }

Other invalid declarations or arguments:

parse(); // {}
parse(null); // {}
parse(1); // {}
parse(true); // {}
parse('top:'); // {}
parse(':12px'); // {}
parse(':'); // {}
parse(';'); // {}

The following values will throw an error:

parse('top'); // Uncaught Error: property missing ':'
parse('/*'); // Uncaught Error: End of comment missing

Options

reactCompat

When option reactCompat is true, the vendor prefix will be capitalized:

parse(
  `
    -webkit-transition: all 4s ease;
    -moz-transition: all 4s ease;
    -ms-transition: all 4s ease;
    -o-transition: all 4s ease;
    -khtml-transition: all 4s ease;
  `,
  { reactCompat: true },
);

Output:

{
  "WebkitTransition": "all 4s ease",
  "MozTransition": "all 4s ease",
  "msTransition": "all 4s ease",
  "OTransition": "all 4s ease",
  "KhtmlTransition": "all 4s ease"
}

This removes the React warning:

Warning: Unsupported vendor-prefixed style property %s. Did you mean %s?%s", "oTransition", "OTransition"

Testing

Run tests with coverage:

npm test

Run tests in watch mode:

npm run test:watch

Lint files:

npm run lint

Fix lint errors:

npm run lint:fix

Release

Release and publish are automated by Release Please.

Special Thanks

License

MIT

taskfasthooksmochaObject.entriesform-validationarraylinuxfunctionsprettysameValueZerospawnsliceeventDispatcherchannelgloboptionregular expressiondatecallbackReactiveExtensionsfsfindLastreduceWeakMapformatfoldernegativenativeObject.valuesgradients cssformArrayBuffer.prototype.sliceshamasciitrimLeftdatapromisecode pointsvaluesmkdirswgetpoint-freethrottlegdprcompilerterminalparentcallsidees2018genericsurlsFunction.prototype.namejestoffseteventsArray.prototype.filterfixed-widthanimationclassnamematchesqueuel10nUnderscorecolorsiswatchingintrinsicschemacmdfast-clonebrowserURLSymbol.toStringTagsymlinksjson-schema-validatorjsdifffigletserializercommand-linereadablestreamredactassigntrimStartuninstallWeakSetArray.prototype.flatdataviewsignalpnpm9autoprefixermixinscheckfullwidthboundelectroninspectObject.getPrototypeOfinferencecommanderviewdefineexpressionstreamcurriedbrowserslistnamesmimespinnerArray.prototype.findLastIndexlogphonewebsiteconfigstyleguidewalkpathes2016runtimeworkspace:*typessigtermbreakhashbddreact animationenumerablerecursivesuperagentconfigurablepackage.jsonwatchFilecss lessInt32ArrayjQueryutilityES2023performantextradirtoolsprototypeflatspinnerseslintpluginaccessibilityi18nansieslintconfiglazysortedregularregexparraysmovesharedarraybufferdeleteapolloRFC-6455es6expresscomparebyteOffsettypedsymbolsafesetImmediatefast-deep-cloneES2018httpvalidationpuresuperstructpersistentsetchaimulti-packageObservablestoSortedopenspipeES7extendCSSStyleDeclarationchromiumsanitizationidleInt8Arraysiginttddframerstylingspringbufferfile systempackagestapwebbundlerdirectory.envconstregexwritablefastcloneTypeBoxECMAScript 7everysymlinkArray.prototype.containsauthenticationtypesafeexitObservableasynchookformlinkbusytypelook-upfunctionalmkdirppassworditeratordependenciesfastifyfileBigUint64ArrayjasminenodeESgroupByenvrm -rfsymbolsprefixxhrwidthpluginbyteimmerclassesredux-toolkitJSONtostringtagrangeerrorobjectStreamdeepcloneiterateimmutablekoreanshellutilitiesrm -frjsonargumenttscoreargsnopeawaitjavascriptguidexecutableexeio-tsshimtoStringTagassertkeypolyfillprogresseventEmitterstatusconcatextensionloggingstreamshandlerssetPrototypeOfInt16ArraywaapiURLSearchParamseditorunicodeFloat64Arraygetoptstylesloadingxdg-openrequestyuptypeofmkdirpushopenerror-handlingqueueMicrotaskwalkingassertionminimalajvauthbootstrap lessdataViewlengthString.prototype.trimvisualbufferspopmotiontacitchildquerystringpyyamlSymbolconcurrencythreeartjsxoptimizerframeworkregular expressionsECMAScript 2016callboundscheme-validationinternal slotcopyfullbcryptMicrosoftobjrapidquotepropbindvalidatees5es8testerdescriptoropenerdescriptorscachetranspilerdependency managerstyled-componentsweaksetsharedES5HyBicurlES2015Arrayflagssyntaxerrorcall-boundpropertythroatoncevalidforEachreduxastStyleSheetES3picomatchzeroprivatecolorinstallerlrufindLastIndexresolveECMAScript 3duplexsettingscensoruuidexecpropertiesjsonschemainternaltapemodulesratemime-dbserializationArrayBuffer#sliceerrorpromisesairbnb__proto__var-0timees-shim APIestreeprotoECMAScript 2019ttydeeptermloggerescapefunctionutil.inspectrobustwordwrapawesomesauceappcryptocolumnsxtermutils[[Prototype]]validatorreact-hookscss variableES2021optimistdom-testing-libraryfseventscollection.es6cryptfind-upargparsestarttrimRightvaluees-shimsefficienttyped arraymatchargves-abstractpackageMapinvariantreactcharacterqueryassertscontains_.extendES2019BigInt64ArrayString.prototype.matchAllfastcopyvariables in csslaunchhttpsfull-widthqsdeep-copystringifierdeep-cloneRegExp#flagstoobjectprunewaitgroupreadablepositivecsspostcss-pluginmimetypesstarterUint32Arrayjson-schema-validationdeterministiceslintsomehasOwnpreserve-symlinksprotobufmatchAllponyfillECMAScript 5getPrototypeOfbyteLengthsignalsECMAScript 6browserlistcharacterscjkcodesbabel-coreObjectenderES8hardlinksurliterationshrinkwrapstringifyformatting$.extendschemecommandreadclibootstrap csslessconsume3dreact posetouchfast-copysyntaxrequireenvironmentecmascriptECMAScript 2022transpilefindnegative zeroECMAScript 2023CSSlimitES2020reducerequalutilmapRxflatMapharmonyavamrucollectionpatchAsyncIterator256processtypedarrayECMAScript 2021traverseindicatordatastructurecorscss-in-jstoArraycolumnlastremoveyamlincludesdomhigher-ordergetintrinsicIteratorupmake dirtestingYAMLfilterbluebirdequalitytelephonestreams2ES2016slotprivate dataoutputjapanesedescriptiongetterObject.definePropertyinputjsES6jwtuser-streamsomitECMAScript 2017chineseECMAScript 2020structuredClonebannerclonevestnpmlintdefinePropertysearchstableapimobilelockfilewindowsbatchwarninggetsortratelimitietrimtc39watcherUint8ClampedArrayrgbArray.prototype.flattenmodulereusees2015a11ybabelRegExp.prototype.flagsFloat32ArrayReactiveXclass-validatorjsonpathbundlingcreateObject.assignramdajoiArrayBuffereast-asian-widthstringfantasy-landtypanionTypeScriptECMAScript 2015exit-codecall-bindcompile lessmetadataentriesemitJSON-Schemafplinewrapesmergediffmiddlewarepreprocessortextpackage managerweakmapcomputed-typeslibphonenumberhelpersES2017ajaxES2022colourcss nestinginstallmonorepoposetrimEndarktypegraphqlPromisespeedWebSocketnodejsconsolenested cssgesturesserializeshebangjsdomrmdirconcatMapinterruptswordbreakArray.prototype.flatMapxssparseless cssdeepcopystylearraybuffercallbindparserUint8ArraySetless.jsreal-timesetterargumentsstylesheetcore-jsclienttestprotocol-buffersworkerwhichArray.prototype.includesencryptiondotenvtoolkitgradients css3sanitizeStreamsletmacoses2017spectypescripteslint-plugindraglanguageObject.is@@toStringTagidchromehasstatelessnamecircularrmESnextparentsflattenkarmanumberWebSocketsirqReflect.getPrototypeOfwritejson-schemarandomlimitedfromreact-hook-formoperating-systemObject.fromEntriesUint16ArrayRxJStakewrapkeysfast-deep-copygetOwnPropertyDescriptorlesscssdropemojiwhatwgPushmaketypedarrayslistenersrfc4122debuglooktslibless mixinsreact-testing-librarycoercibleTypedArrayconnect6to5Object.keysflagpostcsswatchmomentperformanceArray.prototype.findLastclassnamesformssequencefindup0es7accessorzodECMAScript 2018
1.0.0

14 days ago