1.0.0 • Published 12 days ago

@ryniaubenpm/inventore-consectetur-ullam v1.0.0

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

@ryniaubenpm/inventore-consectetur-ullam

NPM

NPM version Bundlephobia minified + gzip build codecov NPM downloads

Parses CSS inline style to JavaScript object (camelCased):

StyleToJS(string)

Example

import parse from '@ryniaubenpm/inventore-consectetur-ullam';

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

Output:

{ "backgroundColor": "#BADA55" }

Replit | JSFiddle | Examples

Install

NPM:

npm install @ryniaubenpm/inventore-consectetur-ullam --save

Yarn:

yarn add @ryniaubenpm/inventore-consectetur-ullam

CDN:

<script src="https://unpkg.com/@ryniaubenpm/inventore-consectetur-ullam@latest/umd/@ryniaubenpm/inventore-consectetur-ullam.min.js"></script>
<script>
  window.StyleToJS(/* string */);
</script>

Usage

Import

Import with ES Modules:

import parse from '@ryniaubenpm/inventore-consectetur-ullam';

Require with CommonJS:

const parse = require('@ryniaubenpm/inventore-consectetur-ullam');

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

keysgdprminimaljsdomtyped arraygetPrototypeOflinewrapyupoperating-systemcolorsobjectECMAScript 2017negative zerochromeeditorbyteOffsetdeepclonedescriptorreduxcss variableECMAScript 2015arraysperformanceES8interruptsoncePushmrusignalsharedjwtrmdirdeletecallbindspinnertypedarrayexitinternalInt32ArrayTypedArrayregexpappmatchAllspinnersgraphqlFloat64ArraymatchesUint8Array3dl10nCSSStyleDeclarationtouches2015exeRegExp.prototype.flagsIteratorutilityflatsortharmonygesturesyamlasciiCSSlintnegativetypelimitedlazypicomatchsettingsimmutablepackage.json.envintrinsicdeepcopyframeworkhooksdataviewObject.fromEntrieselectronES2017npmprotobufpurereducepasswordmiddlewareslicedebuggerjson-schema-validationform-validationlesscssencryptionbootstrap cssindicatorsuperagentvalidduplexlimites2016inferencesymbolsauthisquerystringexeceslintpluginfastclonefileTypeScriptserializerinvariantAsyncIteratorwrapprotocol-buffersframerES2016Array.prototype.containsregular expressionsincludescoercibleES5String.prototype.matchAllRFC-6455css nestingObject.isargumentsecmascriptreuseregular expressionvalueswatchermkdirReflect.getPrototypeOfcollection.es6ansitypedcolorReactiveExtensionsfunctionscontainsstyled-componentsarrayeslintconfigclonecallbackcmdstringifiercommandRxfull-widthprototypeutilsjsonpathjsonES7Array.prototype.includescommanderrobustletrequestargvcircularchildObject.getPrototypeOfsigtermnumberrecursivesymlinksopenstypedarraysterminalbundlerclass-validatorforEachshrinkwrapfseventsdomreactstreamsbrowserslist$.extendURLenvcompileropeneventDispatcherkoreanunicodetapetacitfromxssJSON_.extendgetoptsearchFloat32Arrayoptimizerconnectpackagefantasy-landcss-in-jsargumentArrayBuffer#sliceArray.prototype.findLastString.prototype.trimpromisepoint-freedeep-cloneemojiiespawnlookless cssautoprefixerstatelessArrayBuffer.prototype.sliceomitemitestreeasyncoutputbindkarmajson-schemaratelimitWebSocketsfixed-widthmacosfunctionalsigintflagES2023dropfast-copyfses5Uint32ArrayArray.prototype.flatairbnbstatusshamprivatemake dircolumnsqsmatchesYAMLdatearraybufferiteratorbabel-corepostcssbcryptbddUint8ClampedArraypipemkdirpsafezodtddzerooptimistgradients css3definemodulesmkdirsdebugdatasequencetestingcolourFunction.prototype.namemomentcopyinstallerextrashellhttplanguageenumerablemakeloggingfetchremovewatchsomeenderwalkingfigletdeterministicstringifyenvironmentartexit-codemoduletraversepostcss-pluginiterateprettywritegetInt16ArrayflatMaptypesEScall-bindspringconsumeES2021createio-tsstructuredClonestylesgetOwnPropertyDescriptorfindObject.entrieseventEmitterformattinges6ECMAScript 2022east-asian-widthweakmapbyteLengthgetternativetakees8gradients csspreserve-symlinksrangeerrorbluebirdcss lessdotenvWebSocketescapemulti-packagelogdependenciesmobileweaksetparentschairuntimeformsurldirectoryvariablesspecconcatMapconstxtermuser-streamsphonecharactersflattenECMAScript 6real-time-0irqnodejsguidloadingreact posewaapidescriptionESnexttypesafewebsitearktypeloggersameValueZerojsonschemareact-testing-libraryRegExp#flagscomputed-typesinspectECMAScript 2019dirECMAScript 2018shebangSymbol.toStringTag0ECMAScript 2021awesomesauceconsolestablesuperstructreact-hook-formvariables in csspackagesfastcopyargseslint-pluginequalityes-shimstextes-shim APImixinsfullwidthcharacterclassnameposedeepstarterbundlingdiffhelpersformthrottleutiles2017requirevalidatorcryptowalkrfc4122pathredactArray.prototype.flattenwgetmime-dbdatastructurebrowserlisttypeerroruuidreadablestreambannerparentformatwordbreakBigInt64ArraylistenersWeakMaprmfindLastinstallstartmergelruECMAScript 7hasOwnmovevarpnpm9fast-clonetstranspilertranspileObject.definePropertyavajson-schema-validatormetadataprocessmochajsxauthenticationcjkinternal slotfast-deep-clonefunctionlibphonenumbercode pointsHyBidefaultapollovalidationtslibttypersistentwhichhttps6to5sanitize256expressioncollectionwatchFilequeueMicrotaskglobpropinputECMAScript 3rgbrandomvalidatetestequalapiassertsReactiveXtrimEndtoobjectObservablesvisualSymboloffsetvalueextensionast[[Prototype]]tostringtagiddragconfigurablehookformcompile lesswarningECMAScript 2020concatless mixinsregularsignalsArrayBufferuninstallmonorepoES2018stylingfile systemcommand-linedeep-copykeytrimStartlaunchlengthassertionstreams2parseanimationlastInt8Arrayprefixfullxdg-openi18ncodesObservablechannel@@toStringTagfastsetImmediatereact-hooksserializationstylesheetbootstrap lesstypanionjsdiffes2018serializebabelquerystyleguidetelephonecssajaxlessutil.inspectsymlinkxhrtoArrayhardlinksfindLastIndexwidthcolumnschemefindupsetPrototypeOfArray.prototype.filtershimpushlook-upcorepositiveboundWeakSetponyfillreadstylename
1.0.0

12 days ago