Socket
Socket
Sign inDemoInstall

json-css-module-loader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-css-module-loader - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.npmignore

35

index.js

@@ -0,14 +1,35 @@

const path = require('path');
const JSON_EXT = '.json';
module.exports = function(source, sourceMap) {
var fileName = this.resourcePath;
// Remove the .json ext, will be .css / .scss / .styl etc... now
// to be picked up by other loaders
var cssFileName = this.resourcePath.replace(/.json$/, '');
const fileName = this.resourcePath;
const formatExt = path.extname(fileName);
// There can be double ext, ie. file.css.json
const strippedFileName = path.basename(fileName, formatExt);
const optionalSecondExt = path.extname(strippedFileName);
let outputSource;
let value;
if (formatExt === JSON_EXT) {
value = typeof source === "string" ? JSON.parse(source) : source;
outputSource = `module.exports = ${JSON.stringify(value)}`
} else {
value = source.trim();
outputSource = value;
}
// Remove the extension, will be .css / .scss / .styl etc...
// now to be picked up by other loaders
const extRegExp = new RegExp(optionalSecondExt + formatExt + '$');
const cssFileName = fileName.replace(extRegExp, '.css');
this.cacheable && this.cacheable();
var value = typeof source === "string" ? JSON.parse(source) : source;
this.value = [value];
this.value = [ value ];
var output = `require('${cssFileName}');\nmodule.exports = ${JSON.stringify(value)} ;`;
var output = `require('${cssFileName}');\n${outputSource};`;
return output;
}

8

package.json
{
"name": "json-css-module-loader",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha"
},
"devDependencies": {
"mocha": "^3.1.2",
"sinon": "^1.17.7"
},
"author": "Tom Dye",
"license": "ISC"
}
# Json Css Module Loader
[![Build Status](https://travis-ci.org/tomdye/json-css-module-loader.svg?branch=master)](https://travis-ci.org/tomdye/json-css-module-loader)
[![npm version](https://badge.fury.io/js/json-css-module-loader.svg)](https://badge.fury.io/js/json-css-module-loader)
Webpack loader to load css-module json output and the corresponding css file.

@@ -27,2 +30,4 @@ ie. loading `myApp.css.json` will provide the requiring module with the css-module

This loader is adapted from the [`json-loader`](https://github.com/webpack/json-loader);
MIT (http://www.opensource.org/licenses/mit-license.php)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc