New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-v-model

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-v-model - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

67

dist/create-v-model.js
import { computed } from 'vue';
/**
* @typedef {import('vue').WritableComputedRef} ModelComputed - Ref containing v-model
*/
const createEmitter = (emit, modelName) => v => emit(`update:${modelName}`, v);
const getModifierName = modelName => modelName === 'modelValue' ? 'modelModifiers' : `${modelName}Modifiers`;
const getOnUpdateName = modelName => `onUpdate:${modelName}`;
/**
* @type {() => ({})} emptyObjectFactory
*/
const emptyObjectFactory = () => ({});
const createModelFactory = ({ modelName = 'modelValue', modifier } = {}) => {
return ({ props, emit } = {}) => {
/**
* Creates a factory of createModel functions
* @arg {object} args
* @arg {string} [args.modelName = 'modelValue'] - the NAME of the model in v-model:NAME
* @arg {function} [args.modifier]
* @returns {function({ props: object, emit?: function }): ModelComputed}
*/
function createModelFactory({ modelName = 'modelValue', modifier } = {}) {
return ({ props, emit }) => {
const setter = emit ? createEmitter(emit, modelName) : props[getOnUpdateName(modelName)];

@@ -18,18 +33,40 @@ const modifierName = getModifierName(modelName);

}
};
}
const createModel = ({ props, emit, modelName = 'modelValue', modifier } = {}) => createModelFactory({ modelName, modifier })({ props, emit });
/**
* Create a Ref that will get/set the v-model
* @arg {object} args
* @arg {object} args.props - the Reactive props object from setup
* @arg {function} [args.emit] - the emit function from setup
* @arg {string} [args.modelName = 'modelValue'] - the NAME of the model in v-model:NAME
* @arg {function} [args.modifier] - a modifier function to be called on each set call
* @returns {ModelComputed}
*/
function createModel({ props, emit, modelName = 'modelValue', modifier }) {
return createModelFactory({ modelName, modifier })({ props, emit })
}
const modelProps = ({ modelName = 'modelValue', modelType = null, modelDefault, modifierDefault = emptyObjectFactory } = {}) => ({
[modelName]: {
type: modelType,
default: modelDefault
},
[getModifierName(modelName)]: {
type: Object,
default: modifierDefault
},
[getOnUpdateName(modelName)]: Function
});
/**
* Get the props needed to define a v-model
* @arg {object} args
* @arg {string} [args.modelName = 'modelValue'] - the NAME of the model in v-model:NAME
* @arg {any} [args.modelType = null] - the type the model should receive
* @arg {any} [args.modelDefault] - the default for the model (usually if not set)
* @arg {any} [args.modifierDefault = emptyObjectFactory] - the default for the modelModifiers value
* @returns {object} - props specification
*/
function modelProps({ modelName = 'modelValue', modelType = null, modelDefault, modifierDefault = emptyObjectFactory } = {}) {
return {
[modelName]: {
type: modelType,
default: modelDefault
},
[getModifierName(modelName)]: {
type: Object,
default: modifierDefault
},
[getOnUpdateName(modelName)]: Function
}
}
export { createModel, createModelFactory, modelProps };
{
"name": "create-v-model",
"version": "2.1.0",
"version": "2.1.1",
"description": "create v-model bindings quickly and easily - without having to remember which props to use",

@@ -15,2 +15,3 @@ "files": [

"module": "dist/create-v-model.js",
"types": "./types/index.d.ts",
"exports": {

@@ -22,4 +23,5 @@ "import": "./dist/create-v-model.js",

"scripts": {
"types": "tsc",
"build": "rollup -c",
"preversion": "npm run build",
"preversion": "npm run types && npm run build",
"version": "npm publish --access public",

@@ -37,2 +39,3 @@ "postversion": "git push --follow-tags",

"sinon": "^9.2.2",
"typescript": "^4.3.5",
"uvu": "^0.5.1",

@@ -39,0 +42,0 @@ "vue": "^3.0.4"

@@ -41,2 +41,3 @@ # create-v-model

modelType: any = null,
modelDefault: any,
modifierDefault: any = (() => ({}))

@@ -49,2 +50,3 @@ })

- **modelType**: an optional type to specify the model should be
- **modelDefault**: an optional value to specify the intial value of the model (typically used for [absent prop detection](https://github.com/vuejs/vue-next/blob/master/CHANGELOG.md#310-2021-06-07))
- **modifierDefault**: an optional alternative default for the _modelModifiers_ prop (or equivalent for named models)

@@ -51,0 +53,0 @@

Sorry, the diff of this file is not supported yet

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