Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vee-validate/i18n

Package Overview
Dependencies
Maintainers
1
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vee-validate/i18n - npm Package Compare versions

Comparing version 4.12.8 to 4.13.0

5

dist/vee-validate-i18n.d.ts

@@ -13,2 +13,6 @@ interface FieldValidationMetaInfo {

type ValidationMessageGenerator = (ctx: FieldValidationMetaInfo) => string;
type InterpolateOptions = {
prefix: string;
suffix: string;
};

@@ -25,2 +29,3 @@ type ValidationMessageTemplate = ValidationMessageGenerator | string;

declare function localize(locale: string, dictionary?: PartialI18nDictionary): ValidationMessageGenerator;
declare function localize(locale: string, dictionary?: PartialI18nDictionary, interpolateOptions?: InterpolateOptions): ValidationMessageGenerator;
/**

@@ -27,0 +32,0 @@ * Sets the locale

33

dist/vee-validate-i18n.esm.js
/**
* vee-validate v4.12.8
* vee-validate v4.13.0
* (c) 2024 Abdelrahman Awad

@@ -49,4 +49,6 @@ * @license MIT

*/
function interpolate(template, values) {
return template.replace(/(\d:)?{([^}]+)}/g, function (_, param, placeholder) {
function interpolate(template, values, options) {
const { prefix, suffix } = options;
const regExp = new RegExp(`([0-9]:)?${prefix}([^${suffix}]+)${suffix}`, 'g');
return template.replace(regExp, function (_, param, placeholder) {
if (!param || !values.params) {

@@ -57,11 +59,11 @@ return placeholder in values

? values.params[placeholder]
: `{${placeholder}}`;
: `${prefix}${placeholder}${suffix}`;
}
// Handles extended object params format
if (!Array.isArray(values.params)) {
return placeholder in values.params ? values.params[placeholder] : `{${placeholder}}`;
return placeholder in values.params ? values.params[placeholder] : `${prefix}${placeholder}${suffix}`;
}
// Extended Params exit in the format of `paramIndex:{paramName}` where the index is optional
const paramIndex = Number(param.replace(':', ''));
return paramIndex in values.params ? values.params[paramIndex] : `${param}{${placeholder}}`;
return paramIndex in values.params ? values.params[paramIndex] : `${param}${prefix}${placeholder}${suffix}`;
});

@@ -71,9 +73,10 @@ }

class Dictionary {
constructor(locale, dictionary) {
constructor(locale, dictionary, interpolateOptions = { prefix: '{', suffix: '}' }) {
this.container = {};
this.locale = locale;
this.interpolateOptions = interpolateOptions;
this.merge(dictionary);
}
resolve(ctx) {
return this.format(this.locale, ctx);
resolve(ctx, interpolateOptions) {
return this.format(this.locale, ctx, interpolateOptions);
}

@@ -91,3 +94,3 @@ getLocaleDefault(locale, field) {

}
format(locale, ctx) {
format(locale, ctx, interpolateOptions) {
var _a, _b, _c, _d, _e;

@@ -99,3 +102,5 @@ let message;

message = this.getLocaleDefault(locale, name) || `${fieldName} is not valid`;
return isCallable(message) ? message(ctx) : interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName }));
return isCallable(message)
? message(ctx)
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName }), interpolateOptions !== null && interpolateOptions !== void 0 ? interpolateOptions : this.interpolateOptions);
}

@@ -109,3 +114,3 @@ // find if specific message for that field was specified.

? message(ctx)
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName, params: rule.params }));
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName, params: rule.params }), interpolateOptions !== null && interpolateOptions !== void 0 ? interpolateOptions : this.interpolateOptions);
}

@@ -117,5 +122,5 @@ merge(dictionary) {

const DICTIONARY = new Dictionary('en', {});
function localize(locale, dictionary) {
function localize(locale, dictionary, interpolateOptions) {
const generateMessage = ctx => {
return DICTIONARY.resolve(ctx);
return DICTIONARY.resolve(ctx, interpolateOptions);
};

@@ -122,0 +127,0 @@ if (typeof locale === 'string') {

/**
* vee-validate v4.12.8
* vee-validate v4.13.0
* (c) 2024 Abdelrahman Awad

@@ -55,4 +55,6 @@ * @license MIT

*/
function interpolate(template, values) {
return template.replace(/(\d:)?{([^}]+)}/g, function (_, param, placeholder) {
function interpolate(template, values, options) {
const { prefix, suffix } = options;
const regExp = new RegExp(`([0-9]:)?${prefix}([^${suffix}]+)${suffix}`, 'g');
return template.replace(regExp, function (_, param, placeholder) {
if (!param || !values.params) {

@@ -63,11 +65,11 @@ return placeholder in values

? values.params[placeholder]
: `{${placeholder}}`;
: `${prefix}${placeholder}${suffix}`;
}
// Handles extended object params format
if (!Array.isArray(values.params)) {
return placeholder in values.params ? values.params[placeholder] : `{${placeholder}}`;
return placeholder in values.params ? values.params[placeholder] : `${prefix}${placeholder}${suffix}`;
}
// Extended Params exit in the format of `paramIndex:{paramName}` where the index is optional
const paramIndex = Number(param.replace(':', ''));
return paramIndex in values.params ? values.params[paramIndex] : `${param}{${placeholder}}`;
return paramIndex in values.params ? values.params[paramIndex] : `${param}${prefix}${placeholder}${suffix}`;
});

@@ -77,9 +79,10 @@ }

class Dictionary {
constructor(locale, dictionary) {
constructor(locale, dictionary, interpolateOptions = { prefix: '{', suffix: '}' }) {
this.container = {};
this.locale = locale;
this.interpolateOptions = interpolateOptions;
this.merge(dictionary);
}
resolve(ctx) {
return this.format(this.locale, ctx);
resolve(ctx, interpolateOptions) {
return this.format(this.locale, ctx, interpolateOptions);
}

@@ -97,3 +100,3 @@ getLocaleDefault(locale, field) {

}
format(locale, ctx) {
format(locale, ctx, interpolateOptions) {
var _a, _b, _c, _d, _e;

@@ -105,3 +108,5 @@ let message;

message = this.getLocaleDefault(locale, name) || `${fieldName} is not valid`;
return isCallable(message) ? message(ctx) : interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName }));
return isCallable(message)
? message(ctx)
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName }), interpolateOptions !== null && interpolateOptions !== void 0 ? interpolateOptions : this.interpolateOptions);
}

@@ -115,3 +120,3 @@ // find if specific message for that field was specified.

? message(ctx)
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName, params: rule.params }));
: interpolate(message, Object.assign(Object.assign({}, form), { field: fieldName, params: rule.params }), interpolateOptions !== null && interpolateOptions !== void 0 ? interpolateOptions : this.interpolateOptions);
}

@@ -123,5 +128,5 @@ merge(dictionary) {

const DICTIONARY = new Dictionary('en', {});
function localize(locale, dictionary) {
function localize(locale, dictionary, interpolateOptions) {
const generateMessage = ctx => {
return DICTIONARY.resolve(ctx);
return DICTIONARY.resolve(ctx, interpolateOptions);
};

@@ -128,0 +133,0 @@ if (typeof locale === 'string') {

/**
* vee-validate v4.12.8
* vee-validate v4.13.0
* (c) 2024 Abdelrahman Awad
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VeeValidateI18n={})}(this,(function(e){"use strict";function t(e){return"function"==typeof e}function o(e){if(!function(e){return"object"==typeof e&&null!==e}(e)||"[object Object]"!==function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}(e))return!1;if(null===Object.getPrototypeOf(e))return!0;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function n(e,t){return Object.keys(t).forEach((i=>{if(o(t[i])&&o(e[i]))return e[i]||(e[i]={}),void n(e[i],t[i]);e[i]=t[i]})),e}function i(e,t){return e.replace(/(\d:)?{([^}]+)}/g,(function(e,o,n){if(!o||!t.params)return n in t?t[n]:t.params&&n in t.params?t.params[n]:`{${n}}`;if(!Array.isArray(t.params))return n in t.params?t.params[n]:`{${n}}`;const i=Number(o.replace(":",""));return i in t.params?t.params[i]:`${o}{${n}}`}))}const l=new class{constructor(e,t){this.container={},this.locale=e,this.merge(t)}resolve(e){return this.format(this.locale,e)}getLocaleDefault(e,t){var o,n,i,l,r;return(null===(i=null===(n=null===(o=this.container[e])||void 0===o?void 0:o.fields)||void 0===n?void 0:n[t])||void 0===i?void 0:i._default)||(null===(r=null===(l=this.container[e])||void 0===l?void 0:l.messages)||void 0===r?void 0:r._default)}resolveLabel(e,t,o){var n,i,l,r;return o?(null===(i=null===(n=this.container[e])||void 0===n?void 0:n.names)||void 0===i?void 0:i[o])||o:(null===(r=null===(l=this.container[e])||void 0===l?void 0:l.names)||void 0===r?void 0:r[t])||t}format(e,o){var n,l,r,a,s;let c;const{rule:u,form:d,label:f,name:v}=o,p=this.resolveLabel(e,v,f);return u?(c=(null===(r=null===(l=null===(n=this.container[e])||void 0===n?void 0:n.fields)||void 0===l?void 0:l[v])||void 0===r?void 0:r[u.name])||(null===(s=null===(a=this.container[e])||void 0===a?void 0:a.messages)||void 0===s?void 0:s[u.name]),c||(c=this.getLocaleDefault(e,v)||`${p} is not valid`),t(c)?c(o):i(c,Object.assign(Object.assign({},d),{field:p,params:u.params}))):(c=this.getLocaleDefault(e,v)||`${p} is not valid`,t(c)?c(o):i(c,Object.assign(Object.assign({},d),{field:p})))}merge(e){n(this.container,e)}}("en",{});function r(e,t){const o=e=>l.resolve(e);return"string"==typeof e?(l.locale=e,t&&l.merge({[e]:t}),o):(l.merge(e),o)}e.loadLocaleFromURL=async function(e){try{const t=await fetch(e,{headers:{"content-type":"application/json"}}).then((e=>e.json()));if(!t.code)return void console.error("Could not identify locale, ensure the locale file contains `code` field");r({[t.code]:t})}catch(e){console.error("Failed to load locale ")}},e.localize=r,e.setLocale=function(e){l.locale=e}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VeeValidateI18n={})}(this,(function(e){"use strict";function t(e){return"function"==typeof e}function o(e){if(!function(e){return"object"==typeof e&&null!==e}(e)||"[object Object]"!==function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}(e))return!1;if(null===Object.getPrototypeOf(e))return!0;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function n(e,t){return Object.keys(t).forEach((i=>{if(o(t[i])&&o(e[i]))return e[i]||(e[i]={}),void n(e[i],t[i]);e[i]=t[i]})),e}function i(e,t,o){const{prefix:n,suffix:i}=o,l=new RegExp(`([0-9]:)?${n}([^${i}]+)${i}`,"g");return e.replace(l,(function(e,o,l){if(!o||!t.params)return l in t?t[l]:t.params&&l in t.params?t.params[l]:`${n}${l}${i}`;if(!Array.isArray(t.params))return l in t.params?t.params[l]:`${n}${l}${i}`;const r=Number(o.replace(":",""));return r in t.params?t.params[r]:`${o}${n}${l}${i}`}))}const l=new class{constructor(e,t,o={prefix:"{",suffix:"}"}){this.container={},this.locale=e,this.interpolateOptions=o,this.merge(t)}resolve(e,t){return this.format(this.locale,e,t)}getLocaleDefault(e,t){var o,n,i,l,r;return(null===(i=null===(n=null===(o=this.container[e])||void 0===o?void 0:o.fields)||void 0===n?void 0:n[t])||void 0===i?void 0:i._default)||(null===(r=null===(l=this.container[e])||void 0===l?void 0:l.messages)||void 0===r?void 0:r._default)}resolveLabel(e,t,o){var n,i,l,r;return o?(null===(i=null===(n=this.container[e])||void 0===n?void 0:n.names)||void 0===i?void 0:i[o])||o:(null===(r=null===(l=this.container[e])||void 0===l?void 0:l.names)||void 0===r?void 0:r[t])||t}format(e,o,n){var l,r,a,s,c;let u;const{rule:f,form:d,label:p,name:v}=o,m=this.resolveLabel(e,v,p);return f?(u=(null===(a=null===(r=null===(l=this.container[e])||void 0===l?void 0:l.fields)||void 0===r?void 0:r[v])||void 0===a?void 0:a[f.name])||(null===(c=null===(s=this.container[e])||void 0===s?void 0:s.messages)||void 0===c?void 0:c[f.name]),u||(u=this.getLocaleDefault(e,v)||`${m} is not valid`),t(u)?u(o):i(u,Object.assign(Object.assign({},d),{field:m,params:f.params}),null!=n?n:this.interpolateOptions)):(u=this.getLocaleDefault(e,v)||`${m} is not valid`,t(u)?u(o):i(u,Object.assign(Object.assign({},d),{field:m}),null!=n?n:this.interpolateOptions))}merge(e){n(this.container,e)}}("en",{});function r(e,t,o){const n=e=>l.resolve(e,o);return"string"==typeof e?(l.locale=e,t&&l.merge({[e]:t}),n):(l.merge(e),n)}e.loadLocaleFromURL=async function(e){try{const t=await fetch(e,{headers:{"content-type":"application/json"}}).then((e=>e.json()));if(!t.code)return void console.error("Could not identify locale, ensure the locale file contains `code` field");r({[t.code]:t})}catch(e){console.error("Failed to load locale ")}},e.localize=r,e.setLocale=function(e){l.locale=e}}));
{
"name": "@vee-validate/i18n",
"version": "4.12.8",
"version": "4.13.0",
"description": "Localization module for VeeValidate",

@@ -5,0 +5,0 @@ "author": "Abdelrahman Awad <logaretm1@gmail.com>",

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