[postcss-modules-scope] Add Typescript definitions. (#30626)

This commit is contained in:
Jeow Li Huan
2018-11-19 04:32:45 +08:00
committed by Pranav Senthilnathan
parent fb1c996762
commit 76fca769df
5 changed files with 63 additions and 0 deletions

18
types/postcss-modules-scope/index.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
// Type definitions for postcss-modules-scope 1.1
// Project: https://github.com/css-modules/postcss-modules-scope
// Definitions by: Jeow Li Huan <https://github.com/huan086>
// Definitions: https://github.com/huan086/postcss-plugins-typings
// TypeScript Version: 2.2
import { Plugin } from "postcss";
declare namespace scope {
interface Options {
generateScopedName?: (exportedName: string, path: string, css: string) => string;
}
type Scope = Plugin<Options>;
}
declare const scope: scope.Scope;
export = scope;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"postcss": "7.x.x"
}
}

View File

@@ -0,0 +1,15 @@
import scope = require("postcss-modules-scope");
import { Transformer } from "postcss";
const ap1: Transformer = scope();
const ap2: Transformer = scope({
generateScopedName(exportedName, path, css) {
if (css.substring(0, 7) === "@ignore") {
return exportedName;
}
const sanitisedPath = path.replace(/\.[^\.\/\\]+$/, "").replace(/[\W_]+/g, "_").replace(/^_|_$/g, "");
return `_${sanitisedPath}__${exportedName}`;
}
});

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"postcss-modules-scope-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }