Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add types #33

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "vue-slot-checker provide functions like checking props.",
"main": "dist/vue-slot-checker.common.js",
"unpkg": "dist/vue-slot-checker.umd.min.js",
"types": "types/index.d.ts",
"repository": "https://github.com/mya-ake/vue-slot-checker.git",
"bugs": {
"url": "https://github.com/mya-ake/vue-slot-checker/issues"
Expand All @@ -13,8 +14,10 @@
"scripts": {
"build": "vue-cli-service build --target lib --name vue-slot-checker src/index.js",
"lint": "vue-cli-service lint",
"test": "run-s test:*",
"test:unit": "vue-cli-service test:unit",
"release": "yarn test:unit && yarn build && np"
"test:types": "tsc -p types/test",
"release": "yarn test && yarn build && np"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.0.2",
Expand All @@ -29,6 +32,9 @@
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0",
"np": "^5.1.0",
"npm-run-all": "^4.1.5",
"typescript": "^3.6.4",
"vue": "^2.6.10",
"vue-template-compiler": "^2.5.21"
},
"peerDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './vue';
import {
VueSlotCheckerPlugin,
vueSlotChckerMixin,
VueSlotCheckerOption,
} from './slot-checker';

export default VueSlotCheckerPlugin;

export { vueSlotChckerMixin, VueSlotCheckerOption };
31 changes: 31 additions & 0 deletions types/slot-checker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { VNode, PluginObject } from 'vue';

type SlotValidator =
| {
required: boolean;
}
| {
validator: (slots: VNode[] | undefined) => boolean;
};
type BooleanSlotsDefinition = boolean;
type ArraySlotsDefinition = string[];
type RecordSlotsDefinition = {
default: SlotValidator;
[key: string]: SlotValidator;
};

export type SlotsDefinition =
| BooleanSlotsDefinition
| ArraySlotsDefinition
| RecordSlotsDefinition;

export type VueSlotCheckerOption = {
slient?: boolean;
};

export type VueSlotCheckerPlugin = PluginObject<VueSlotCheckerOption>;

export declare const vueSlotChckerMixin: {
created(): void;
};

46 changes: 46 additions & 0 deletions types/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-unused-vars */
import Vue, { ComponentOptions } from 'vue';
import VueSlotChcker, { vueSlotCheckerMixin } from '../../src/index';

Vue.use(VueSlotChcker);

const Mixin: ComponentOptions<Vue> = {
mixins: [vueSlotCheckerMixin],
};

const BooleanSlots: ComponentOptions<Vue> = {
slots: true,
};

const ArraySlots: ComponentOptions<Vue> = {
slots: ['default'],
};

const RecordSlots: ComponentOptions<Vue> = {
slots: {
default: {
required: true,
},
},
};

const ValidatorRecordSlots: ComponentOptions<Vue> = {
slots: {
default: {
validator() {
return true;
},
},
header: {
validator(slots) {
if (typeof slots === 'undefined') {
return false;
}
return (
typeof slots[0].tag === 'undefined' &&
typeof slots[0].text === 'string'
);
},
},
},
};
13 changes: 13 additions & 0 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"strict": true,
"noEmit": true,
"allowJs": true,
"noUnusedLocals": false,
"lib": ["es5", "dom"]
},
"include": ["*.ts", "../*.d.ts", "../../src/*.js"]
}
8 changes: 8 additions & 0 deletions types/vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Vue from "vue";
import { SlotsDefinition } from './slot-checker'

declare module "vue/types/options" {
interface ComponentOptions<V extends Vue> {
slots?: SlotsDefinition;
}
}
37 changes: 36 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@
webpack-dev-server "^3.4.1"
webpack-merge "^4.2.1"

"@vue/cli-shared-utils@^4.0.3", "@vue/cli-shared-utils@^4.0.4":
"@vue/cli-shared-utils@^4.0.4":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@vue/cli-shared-utils/-/cli-shared-utils-4.0.4.tgz#ef94325c3954eaac60ca4af9a6de355131ae6e3f"
integrity sha512-f8a9MxZJ89zw783gk2yjG6wPu5IHnmrH8whc1jMJhWNKxRTgCkUxevPVQIobiWy1UtMBdDXXOLxd4PRNK9nyxQ==
Expand Down Expand Up @@ -7358,6 +7358,11 @@ memory-fs@^0.4.0, memory-fs@^0.4.1:
errno "^0.1.3"
readable-stream "^2.0.1"

memorystream@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
integrity sha1-htcJCzDORV1j+64S3aUaR93K+bI=

meow@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-5.0.0.tgz#dfc73d63a9afc714a5e371760eb5c88b91078aa4"
Expand Down Expand Up @@ -7997,6 +8002,21 @@ npm-packlist@^1.1.6:
ignore-walk "^3.0.1"
npm-bundled "^1.0.1"

npm-run-all@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/npm-run-all/-/npm-run-all-4.1.5.tgz#04476202a15ee0e2e214080861bff12a51d98fba"
integrity sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==
dependencies:
ansi-styles "^3.2.1"
chalk "^2.4.1"
cross-spawn "^6.0.5"
memorystream "^0.3.1"
minimatch "^3.0.4"
pidtree "^0.3.0"
read-pkg "^3.0.0"
shell-quote "^1.6.1"
string.prototype.padend "^3.0.0"

npm-run-path@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f"
Expand Down Expand Up @@ -8589,6 +8609,11 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

pidtree@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/pidtree/-/pidtree-0.3.0.tgz#f6fada10fccc9f99bf50e90d0b23d72c9ebc2e6b"
integrity sha512-9CT4NFlDcosssyg8KVFltgokyKZIFjoBxw8CTGy+5F38Y1eQWrt8tRayiUOXE+zVKQnYu5BR8JjCtvK3BcnBhg==

pify@^2.0.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
Expand Down Expand Up @@ -11163,6 +11188,11 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.6.4:
version "3.6.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
integrity sha512-unoCll1+l+YK4i4F8f22TaNVPRHcD9PA3yCuZ8g5e0qGqlVlJ/8FSateOLLSagn+Yg5+ZwuPkL8LFUc0Jcvksg==

uglify-js@3.4.x, uglify-js@^3.1.4:
version "3.4.9"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.9.tgz#af02f180c1207d76432e473ed24a28f4a782bae3"
Expand Down Expand Up @@ -11499,6 +11529,11 @@ vue-template-es2015-compiler@^1.9.0:
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825"
integrity sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==

vue@^2.6.10:
version "2.6.10"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==

w3c-hr-time@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"
Expand Down