svelte-i18n
Advanced tools
Comparing version 1.1.2-beta to 1.1.2
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var store=require("svelte/store"),o=_interopDefault(require("object-resolve-path")),r=_interopDefault(require("intl-messageformat")),n=_interopDefault(require("micro-memoize"));const s=({navigator:e,hash:t,search:r,fallback:o}={})=>{let n;const s=(e,t)=>{const r=e.substr(1).split("&").find(e=>0===e.indexOf(t));if(r)return r.split("=").pop()};return"undefined"!=typeof window&&(e&&(n=window.navigator.language||window.navigator.languages[0]),r&&(n=s(window.location.search,r)),t&&(n=s(window.location.hash,t))),n||o};let a,i;const c=n((e,t,o)=>new r(e,t,o)),l=n((e,t)=>i[t][e]||o(i[t],e)),p=(e,t,r=a)=>c(e,r).format(t),f=(e,t,r=a)=>{"string"==typeof t&&(r=t,t=void 0);const o=l(e,r);return o?t?c(o,r).format(t):o:e};f.time=(e,t="short",r)=>p(`{t,time,${t}}`,{t:e},r),f.date=(e,t="short",r)=>p(`{d,date,${t}}`,{d:e},r),f.number=(e,t)=>p("{n,number}",{n:e},t),f.capital=(e,t,r)=>(e=>e.replace(/(^|\s)\S/,e=>e.toUpperCase()))(f(e,t,r)),f.title=(e,t,r)=>(e=>e.replace(/(^|\s)\S/g,e=>e.toUpperCase()))(f(e,t,r)),f.upper=(e,t,r)=>(e=>e.toLocaleUpperCase())(f(e,t,r)),f.lower=(e,t,r)=>(e=>e.toLocaleLowerCase())(f(e,t,r));const m=store.writable({});m.subscribe(e=>{i=e});const u=store.writable({}),d=u.set;u.set=e=>{const t=(e=>{if(i[e])return e;if("string"==typeof e){const t=e.split("-").shift();if(i[t])return t}return null})(e);return t?d(t):(console.warn(`[svelte-i18n] Locale "${e}" not found.`),d(e))},u.update=e=>d(e(a)),u.subscribe(e=>{a=e});const w=store.derived([u,m],()=>f);exports._=w,exports.dictionary=m,exports.format=w,exports.getClientLocale=s,exports.locale=u; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var resolvePath=_interopDefault(require("object-resolve-path")),IntlMessageFormat=_interopDefault(require("intl-messageformat")),memoize=_interopDefault(require("micro-memoize"));function unwrapExports(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function createCommonjsModule(t,e){return t(e={exports:{}},e.exports),e.exports}function getCjsExportFromNamespace(t){return t&&t.default||t}function noop(){}const identity=t=>t;function assign(t,e){for(const n in e)t[n]=e[n];return t}function is_promise(t){return t&&"object"==typeof t&&"function"==typeof t.then}function add_location(t,e,n,o,r){t.__svelte_meta={loc:{file:e,line:n,column:o,char:r}}}function run(t){return t()}function blank_object(){return Object.create(null)}function run_all(t){t.forEach(run)}function is_function(t){return"function"==typeof t}function safe_not_equal(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function not_equal(t,e){return t!=t?e==e:t!==e}function validate_store(t,e){if(!t||"function"!=typeof t.subscribe)throw new Error(`'${e}' is not a store with a 'subscribe' method`)}function subscribe(t,e){const n=t.subscribe(e);return n.unsubscribe?()=>n.unsubscribe():n}function get_store_value(t){let e;return subscribe(t,t=>e=t)(),e}function component_subscribe(t,e,n){t.$$.on_destroy.push(subscribe(e,n))}function create_slot(t,e,n){if(t){const o=get_slot_context(t,e,n);return t[0](o)}}function get_slot_context(t,e,n){return t[1]?assign({},assign(e.$$scope.ctx,t[1](n?n(e):{}))):e.$$scope.ctx}function get_slot_changes(t,e,n,o){return t[1]?assign({},assign(e.$$scope.changed||{},t[1](o?o(n):{}))):e.$$scope.changed||{}}function exclude_internal_props(t){const e={};for(const n in t)"$"!==n[0]&&(e[n]=t[n]);return e}function once(t){let e=!1;return function(...n){e||(e=!0,t.call(this,...n))}}function null_to_empty(t){return null==t?"":t}function set_store_value(t,e,n=e){return t.set(n),e}const has_prop=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),is_client="undefined"!=typeof window;let now=is_client?()=>window.performance.now():()=>Date.now(),raf=is_client?t=>requestAnimationFrame(t):noop;function set_now(t){now=t}function set_raf(t){raf=t}const tasks=new Set;let stylesheet,running=!1;function run_tasks(){tasks.forEach(t=>{t[0](now())||(tasks.delete(t),t[1]())}),(running=tasks.size>0)&&raf(run_tasks)}function clear_loops(){tasks.forEach(t=>tasks.delete(t)),running=!1}function loop(t){let e;return running||(running=!0,raf(run_tasks)),{promise:new Promise(n=>{tasks.add(e=[t,n])}),abort(){tasks.delete(e)}}}function append(t,e){t.appendChild(e)}function insert(t,e,n){t.insertBefore(e,n||null)}function detach(t){t.parentNode.removeChild(t)}function destroy_each(t,e){for(let n=0;n<t.length;n+=1)t[n]&&t[n].d(e)}function element(t){return document.createElement(t)}function element_is(t,e){return document.createElement(t,{is:e})}function object_without_properties(t,e){const n={};for(const o in t)has_prop(t,o)&&-1===e.indexOf(o)&&(n[o]=t[o]);return n}function svg_element(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function text(t){return document.createTextNode(t)}function space(){return text(" ")}function empty(){return text("")}function listen(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}function prevent_default(t){return function(e){return e.preventDefault(),t.call(this,e)}}function stop_propagation(t){return function(e){return e.stopPropagation(),t.call(this,e)}}function self(t){return function(e){e.target===this&&t.call(this,e)}}function attr(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function set_attributes(t,e){const n=Object.getOwnPropertyDescriptors(t.__proto__);for(const o in e)null==e[o]?t.removeAttribute(o):"style"===o?t.style.cssText=e[o]:n[o]&&n[o].set?t[o]=e[o]:attr(t,o,e[o])}function set_svg_attributes(t,e){for(const n in e)attr(t,n,e[n])}function set_custom_element_data(t,e,n){e in t?t[e]=n:attr(t,e,n)}function xlink_attr(t,e,n){t.setAttributeNS("http://www.w3.org/1999/xlink",e,n)}function get_binding_group_value(t){const e=[];for(let n=0;n<t.length;n+=1)t[n].checked&&e.push(t[n].__value);return e}function to_number(t){return""===t?void 0:+t}function time_ranges_to_array(t){const e=[];for(let n=0;n<t.length;n+=1)e.push({start:t.start(n),end:t.end(n)});return e}function children(t){return Array.from(t.childNodes)}function claim_element(t,e,n,o){for(let o=0;o<t.length;o+=1){const r=t[o];if(r.nodeName===e){for(let t=0;t<r.attributes.length;t+=1){const e=r.attributes[t];n[e.name]||r.removeAttribute(e.name)}return t.splice(o,1)[0]}}return o?svg_element(e):element(e)}function claim_text(t,e){for(let n=0;n<t.length;n+=1){const o=t[n];if(3===o.nodeType)return o.data=""+e,t.splice(n,1)[0]}return text(e)}function claim_space(t){return claim_text(t," ")}function set_data(t,e){e=""+e,t.data!==e&&(t.data=e)}function set_input_value(t,e){(null!=e||t.value)&&(t.value=e)}function set_input_type(t,e){try{t.type=e}catch(t){}}function set_style(t,e,n,o){t.style.setProperty(e,n,o?"important":"")}function select_option(t,e){for(let n=0;n<t.options.length;n+=1){const o=t.options[n];if(o.__value===e)return void(o.selected=!0)}}function select_options(t,e){for(let n=0;n<t.options.length;n+=1){const o=t.options[n];o.selected=~e.indexOf(o.__value)}}function select_value(t){const e=t.querySelector(":checked")||t.options[0];return e&&e.__value}function select_multiple_value(t){return[].map.call(t.querySelectorAll(":checked"),t=>t.__value)}function add_resize_listener(t,e){"static"===getComputedStyle(t).position&&(t.style.position="relative");const n=document.createElement("object");let o;return n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"),n.setAttribute("aria-hidden","true"),n.type="text/html",n.tabIndex=-1,n.onload=()=>{(o=n.contentDocument.defaultView).addEventListener("resize",e)},/Trident/.test(navigator.userAgent)?(t.appendChild(n),n.data="about:blank"):(n.data="about:blank",t.appendChild(n)),{cancel:()=>{o&&o.removeEventListener&&o.removeEventListener("resize",e),t.removeChild(n)}}}function toggle_class(t,e,n){t.classList[n?"add":"remove"](e)}function custom_event(t,e){const n=document.createEvent("CustomEvent");return n.initCustomEvent(t,!1,!1,e),n}class HtmlTag{constructor(t,e=null){this.e=element("div"),this.a=e,this.u(t)}m(t,e=null){for(let n=0;n<this.n.length;n+=1)insert(t,this.n[n],e);this.t=t}u(t){this.e.innerHTML=t,this.n=Array.from(this.e.childNodes)}p(t){this.d(),this.u(t),this.m(this.t,this.a)}d(){this.n.forEach(detach)}}let current_component,active=0,current_rules={};function hash(t){let e=5381,n=t.length;for(;n--;)e=(e<<5)-e^t.charCodeAt(n);return e>>>0}function create_rule(t,e,n,o,r,s,a,c=0){const i=16.666/o;let l="{\n";for(let t=0;t<=1;t+=i){const o=e+(n-e)*s(t);l+=100*t+`%{${a(o,1-o)}}\n`}const u=l+`100% {${a(n,1-n)}}\n}`,_=`__svelte_${hash(u)}_${c}`;if(!current_rules[_]){if(!stylesheet){const t=element("style");document.head.appendChild(t),stylesheet=t.sheet}current_rules[_]=!0,stylesheet.insertRule(`@keyframes ${_} ${u}`,stylesheet.cssRules.length)}const d=t.style.animation||"";return t.style.animation=`${d?`${d}, `:""}${_} ${o}ms linear ${r}ms 1 both`,active+=1,_}function delete_rule(t,e){t.style.animation=(t.style.animation||"").split(", ").filter(e?t=>t.indexOf(e)<0:t=>-1===t.indexOf("__svelte")).join(", "),e&&!--active&&clear_rules()}function clear_rules(){raf(()=>{if(active)return;let t=stylesheet.cssRules.length;for(;t--;)stylesheet.deleteRule(t);current_rules={}})}function create_animation(t,e,n,o){if(!e)return noop;const r=t.getBoundingClientRect();if(e.left===r.left&&e.right===r.right&&e.top===r.top&&e.bottom===r.bottom)return noop;const{delay:s=0,duration:a=300,easing:c=identity,start:i=now()+s,end:l=i+a,tick:u=noop,css:_}=n(t,{from:e,to:r},o);let d,p=!0,f=!1;function m(){_&&delete_rule(t,d),p=!1}return loop(t=>{if(!f&&t>=i&&(f=!0),f&&t>=l&&(u(1,0),m()),!p)return!1;if(f){const e=0+1*c((t-i)/a);u(e,1-e)}return!0}),_&&(d=create_rule(t,0,1,a,s,c,_)),s||(f=!0),u(0,1),m}function fix_position(t){const e=getComputedStyle(t);if("absolute"!==e.position&&"fixed"!==e.position){const{width:n,height:o}=e,r=t.getBoundingClientRect();t.style.position="absolute",t.style.width=n,t.style.height=o,add_transform(t,r)}}function add_transform(t,e){const n=t.getBoundingClientRect();if(e.left!==n.left||e.top!==n.top){const o=getComputedStyle(t),r="none"===o.transform?"":o.transform;t.style.transform=`${r} translate(${e.left-n.left}px, ${e.top-n.top}px)`}}function set_current_component(t){current_component=t}function get_current_component(){if(!current_component)throw new Error("Function called outside component initialization");return current_component}function beforeUpdate(t){get_current_component().$$.before_update.push(t)}function onMount(t){get_current_component().$$.on_mount.push(t)}function afterUpdate(t){get_current_component().$$.after_update.push(t)}function onDestroy(t){get_current_component().$$.on_destroy.push(t)}function createEventDispatcher(){const t=get_current_component();return(e,n)=>{const o=t.$$.callbacks[e];if(o){const r=custom_event(e,n);o.slice().forEach(e=>{e.call(t,r)})}}}function setContext(t,e){get_current_component().$$.context.set(t,e)}function getContext(t){return get_current_component().$$.context.get(t)}function bubble(t,e){const n=t.$$.callbacks[e.type];n&&n.slice().forEach(t=>t(e))}const dirty_components=[],intros={enabled:!1},binding_callbacks=[],render_callbacks=[],flush_callbacks=[],resolved_promise=Promise.resolve();let promise,update_scheduled=!1;function schedule_update(){update_scheduled||(update_scheduled=!0,resolved_promise.then(flush))}function tick(){return schedule_update(),resolved_promise}function add_render_callback(t){render_callbacks.push(t)}function add_flush_callback(t){flush_callbacks.push(t)}function flush(){const t=new Set;do{for(;dirty_components.length;){const t=dirty_components.shift();set_current_component(t),update(t.$$)}for(;binding_callbacks.length;)binding_callbacks.pop()();for(let e=0;e<render_callbacks.length;e+=1){const n=render_callbacks[e];t.has(n)||(n(),t.add(n))}render_callbacks.length=0}while(dirty_components.length);for(;flush_callbacks.length;)flush_callbacks.pop()();update_scheduled=!1}function update(t){null!==t.fragment&&(t.update(t.dirty),run_all(t.before_update),t.fragment&&t.fragment.p(t.dirty,t.ctx),t.dirty=null,t.after_update.forEach(add_render_callback))}function wait(){return promise||(promise=Promise.resolve()).then(()=>{promise=null}),promise}function dispatch(t,e,n){t.dispatchEvent(custom_event(`${e?"intro":"outro"}${n}`))}const outroing=new Set;let outros;function group_outros(){outros={r:0,c:[],p:outros}}function check_outros(){outros.r||run_all(outros.c),outros=outros.p}function transition_in(t,e){t&&t.i&&(outroing.delete(t),t.i(e))}function transition_out(t,e,n,o){if(t&&t.o){if(outroing.has(t))return;outroing.add(t),outros.c.push(()=>{outroing.delete(t),o&&(n&&t.d(1),o())}),t.o(e)}}const null_transition={duration:0};function create_in_transition(t,e,n){let o,r,s=e(t,n),a=!1,c=0;function i(){o&&delete_rule(t,o)}function l(){const{delay:e=0,duration:n=300,easing:l=identity,tick:u=noop,css:_}=s||null_transition;_&&(o=create_rule(t,0,1,n,e,l,_,c++)),u(0,1);const d=now()+e,p=d+n;r&&r.abort(),a=!0,add_render_callback(()=>dispatch(t,!0,"start")),r=loop(e=>{if(a){if(e>=p)return u(1,0),dispatch(t,!0,"end"),i(),a=!1;if(e>=d){const t=l((e-d)/n);u(t,1-t)}}return a})}let u=!1;return{start(){u||(delete_rule(t),is_function(s)?(s=s(),wait().then(l)):l())},invalidate(){u=!1},end(){a&&(i(),a=!1)}}}function create_out_transition(t,e,n){let o,r=e(t,n),s=!0;const a=outros;function c(){const{delay:e=0,duration:n=300,easing:c=identity,tick:i=noop,css:l}=r||null_transition;l&&(o=create_rule(t,1,0,n,e,c,l));const u=now()+e,_=u+n;add_render_callback(()=>dispatch(t,!1,"start")),loop(e=>{if(s){if(e>=_)return i(0,1),dispatch(t,!1,"end"),--a.r||run_all(a.c),!1;if(e>=u){const t=c((e-u)/n);i(1-t,t)}}return s})}return a.r+=1,is_function(r)?wait().then(()=>{r=r(),c()}):c(),{end(e){e&&r.tick&&r.tick(1,0),s&&(o&&delete_rule(t,o),s=!1)}}}function create_bidirectional_transition(t,e,n,o){let r=e(t,n),s=o?0:1,a=null,c=null,i=null;function l(){i&&delete_rule(t,i)}function u(t,e){const n=t.b-s;return e*=Math.abs(n),{a:s,b:t.b,d:n,duration:e,start:t.start,end:t.start+e,group:t.group}}function _(e){const{delay:n=0,duration:o=300,easing:_=identity,tick:d=noop,css:p}=r||null_transition,f={start:now()+n,b:e};e||(f.group=outros,outros.r+=1),a?c=f:(p&&(l(),i=create_rule(t,s,e,o,n,_,p)),e&&d(0,1),a=u(f,o),add_render_callback(()=>dispatch(t,e,"start")),loop(e=>{if(c&&e>c.start&&(a=u(c,o),c=null,dispatch(t,a.b,"start"),p&&(l(),i=create_rule(t,s,a.b,a.duration,0,_,r.css))),a)if(e>=a.end)d(s=a.b,1-s),dispatch(t,a.b,"end"),c||(a.b?l():--a.group.r||run_all(a.group.c)),a=null;else if(e>=a.start){const t=e-a.start;s=a.a+a.d*_(t/a.duration),d(s,1-s)}return!(!a&&!c)}))}return{run(t){is_function(r)?wait().then(()=>{r=r(),_(t)}):_(t)},end(){l(),a=c=null}}}function handle_promise(t,e){const n=e.token={};function o(t,o,r,s){if(e.token!==n)return;e.resolved=r&&{[r]:s};const a=assign(assign({},e.ctx),e.resolved),c=t&&(e.current=t)(a);let i=!1;e.block&&(e.blocks?e.blocks.forEach((t,n)=>{n!==o&&t&&(group_outros(),transition_out(t,1,1,()=>{e.blocks[n]=null}),check_outros())}):e.block.d(1),c.c(),transition_in(c,1),c.m(e.mount(),e.anchor),i=!0),e.block=c,e.blocks&&(e.blocks[o]=c),i&&flush()}if(is_promise(t)){const n=get_current_component();if(t.then(t=>{set_current_component(n),o(e.then,1,e.value,t),set_current_component(null)},t=>{set_current_component(n),o(e.catch,2,e.error,t),set_current_component(null)}),e.current!==e.pending)return o(e.pending,0),!0}else{if(e.current!==e.then)return o(e.then,1,e.value,t),!0;e.resolved={[e.value]:t}}}const globals="undefined"!=typeof window?window:global;function destroy_block(t,e){t.d(1),e.delete(t.key)}function outro_and_destroy_block(t,e){transition_out(t,1,1,()=>{e.delete(t.key)})}function fix_and_destroy_block(t,e){t.f(),destroy_block(t,e)}function fix_and_outro_and_destroy_block(t,e){t.f(),outro_and_destroy_block(t,e)}function update_keyed_each(t,e,n,o,r,s,a,c,i,l,u,_){let d=t.length,p=s.length,f=d;const m={};for(;f--;)m[t[f].key]=f;const h=[],g=new Map,b=new Map;for(f=p;f--;){const t=_(r,s,f),c=n(t);let i=a.get(c);i?o&&i.p(e,t):(i=l(c,t)).c(),g.set(c,h[f]=i),c in m&&b.set(c,Math.abs(f-m[c]))}const v=new Set,y=new Set;function F(t){transition_in(t,1),t.m(c,u),a.set(t.key,t),u=t.first,p--}for(;d&&p;){const e=h[p-1],n=t[d-1],o=e.key,r=n.key;e===n?(u=e.first,d--,p--):g.has(r)?!a.has(o)||v.has(o)?F(e):y.has(r)?d--:b.get(o)>b.get(r)?(y.add(o),F(e)):(v.add(r),d--):(i(n,a),d--)}for(;d--;){const e=t[d];g.has(e.key)||i(e,a)}for(;p;)F(h[p-1]);return h}function measure(t){const e={};let n=t.length;for(;n--;)e[t[n].key]=t[n].node.getBoundingClientRect();return e}function get_spread_update(t,e){const n={},o={},r={$$scope:1};let s=t.length;for(;s--;){const a=t[s],c=e[s];if(c){for(const t in a)t in c||(o[t]=1);for(const t in c)r[t]||(n[t]=c[t],r[t]=1);t[s]=c}else for(const t in a)r[t]=1}for(const t in o)t in n||(n[t]=void 0);return n}function get_spread_object(t){return"object"==typeof t&&null!==t?t:{}}const boolean_attributes=new Set(["allowfullscreen","allowpaymentrequest","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"]),invalid_attribute_name_character=/[\s'">/=\u{FDD0}-\u{FDEF}\u{FFFE}\u{FFFF}\u{1FFFE}\u{1FFFF}\u{2FFFE}\u{2FFFF}\u{3FFFE}\u{3FFFF}\u{4FFFE}\u{4FFFF}\u{5FFFE}\u{5FFFF}\u{6FFFE}\u{6FFFF}\u{7FFFE}\u{7FFFF}\u{8FFFE}\u{8FFFF}\u{9FFFE}\u{9FFFF}\u{AFFFE}\u{AFFFF}\u{BFFFE}\u{BFFFF}\u{CFFFE}\u{CFFFF}\u{DFFFE}\u{DFFFF}\u{EFFFE}\u{EFFFF}\u{FFFFE}\u{FFFFF}\u{10FFFE}\u{10FFFF}]/u;function spread(t,e){const n=Object.assign({},...t);e&&(null==n.class?n.class=e:n.class+=" "+e);let o="";return Object.keys(n).forEach(t=>{if(invalid_attribute_name_character.test(t))return;const e=n[t];!0===e?o+=" "+t:boolean_attributes.has(t.toLowerCase())?e&&(o+=" "+t):null!=e&&(o+=" "+t+"="+JSON.stringify(String(e).replace(/"/g,""").replace(/'/g,"'")))}),o}const escaped={'"':""","'":"'","&":"&","<":"<",">":">"};function escape(t){return String(t).replace(/["'&<>]/g,t=>escaped[t])}function each(t,e){let n="";for(let o=0;o<t.length;o+=1)n+=e(t[o],o);return n}const missing_component={$$render:()=>""};function validate_component(t,e){if(!t||!t.$$render)throw"svelte:component"===e&&(e+=" this={...}"),new Error(`<${e}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules`);return t}function debug(t,e,n,o){return console.log(`{@debug} ${t?t+" ":""}(${e}:${n})`),console.log(o),""}let on_destroy,SvelteElement;function create_ssr_component(t){function e(e,n,o,r){const s=current_component;set_current_component({$$:{on_destroy:on_destroy,context:new Map(s?s.$$.context:[]),on_mount:[],before_update:[],after_update:[],callbacks:blank_object()}});const a=t(e,n,o,r);return set_current_component(s),a}return{render:(t={},n={})=>{on_destroy=[];const o={head:"",css:new Set},r=e(o,t,{},n);return run_all(on_destroy),{html:r,css:{code:Array.from(o.css).map(t=>t.code).join("\n"),map:null},head:o.head}},$$render:e}}function add_attribute(t,e,n){return null==e||n&&!e?"":` ${t}${!0===e?"":`=${"string"==typeof e?JSON.stringify(escape(e)):`"${e}"`}`}`}function add_classes(t){return t?` class="${t}"`:""}function bind(t,e,n){has_prop(t.$$.props,e)&&(e=t.$$.props[e]||e,t.$$.bound[e]=n,n(t.$$.ctx[e]))}function create_component(t){t&&t.c()}function claim_component(t,e){t&&t.l(e)}function mount_component(t,e,n){const{fragment:o,on_mount:r,on_destroy:s,after_update:a}=t.$$;o&&o.m(e,n),add_render_callback(()=>{const e=r.map(run).filter(is_function);s?s.push(...e):run_all(e),t.$$.on_mount=[]}),a.forEach(add_render_callback)}function destroy_component(t,e){const n=t.$$;null!==n.fragment&&(run_all(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx={})}function make_dirty(t,e){t.$$.dirty||(dirty_components.push(t),schedule_update(),t.$$.dirty=blank_object()),t.$$.dirty[e]=!0}function init(t,e,n,o,r,s){const a=current_component;set_current_component(t);const c=e.props||{},i=t.$$={fragment:null,ctx:null,props:s,update:noop,not_equal:r,bound:blank_object(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(a?a.$$.context:[]),callbacks:blank_object(),dirty:null};let l=!1;i.ctx=n?n(t,c,(e,n,o=n)=>(i.ctx&&r(i.ctx[e],i.ctx[e]=o)&&(i.bound[e]&&i.bound[e](o),l&&make_dirty(t,e)),n)):c,i.update(),l=!0,run_all(i.before_update),i.fragment=!!o&&o(i.ctx),e.target&&(e.hydrate?i.fragment&&i.fragment.l(children(e.target)):i.fragment&&i.fragment.c(),e.intro&&transition_in(t.$$.fragment),mount_component(t,e.target,e.anchor),flush()),set_current_component(a)}"function"==typeof HTMLElement&&(SvelteElement=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){for(const t in this.$$.slotted)this.appendChild(this.$$.slotted[t])}attributeChangedCallback(t,e,n){this[t]=n}$destroy(){destroy_component(this,1),this.$destroy=noop}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}});class SvelteComponent{$destroy(){destroy_component(this,1),this.$destroy=noop}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(){}}function dispatch_dev(t,e){document.dispatchEvent(custom_event(t,e))}function append_dev(t,e){dispatch_dev("SvelteDOMInsert",{target:t,node:e}),append(t,e)}function insert_dev(t,e,n){dispatch_dev("SvelteDOMInsert",{target:t,node:e,anchor:n}),insert(t,e,n)}function detach_dev(t){dispatch_dev("SvelteDOMRemove",{node:t}),detach(t)}function detach_between_dev(t,e){for(;t.nextSibling&&t.nextSibling!==e;)detach_dev(t.nextSibling)}function detach_before_dev(t){for(;t.previousSibling;)detach_dev(t.previousSibling)}function detach_after_dev(t){for(;t.nextSibling;)detach_dev(t.nextSibling)}function listen_dev(t,e,n,o,r,s){const a=!0===o?["capture"]:o?Array.from(Object.keys(o)):[];r&&a.push("preventDefault"),s&&a.push("stopPropagation"),dispatch_dev("SvelteDOMAddEventListener",{node:t,event:e,handler:n,modifiers:a});const c=listen(t,e,n,o);return()=>{dispatch_dev("SvelteDOMRemoveEventListener",{node:t,event:e,handler:n,modifiers:a}),c()}}function attr_dev(t,e,n){attr(t,e,n),null==n?dispatch_dev("SvelteDOMRemoveAttribute",{node:t,attribute:e}):dispatch_dev("SvelteDOMSetAttribute",{node:t,attribute:e,value:n})}function prop_dev(t,e,n){t[e]=n,dispatch_dev("SvelteDOMSetProperty",{node:t,property:e,value:n})}function dataset_dev(t,e,n){t.dataset[e]=n,dispatch_dev("SvelteDOMSetDataset",{node:t,property:e,value:n})}function set_data_dev(t,e){e=""+e,t.data!==e&&(dispatch_dev("SvelteDOMSetData",{node:t,data:e}),t.data=e)}class SvelteComponentDev extends SvelteComponent{constructor(t){if(!t||!t.target&&!t.$$inline)throw new Error("'target' is a required option");super()}$destroy(){super.$destroy(),this.$destroy=()=>{console.warn("Component was already destroyed")}}}function loop_guard(t){const e=Date.now();return()=>{if(Date.now()-e>t)throw new Error("Infinite loop detected")}}var internal=Object.freeze({__proto__:null,HtmlTag:HtmlTag,SvelteComponent:SvelteComponent,SvelteComponentDev:SvelteComponentDev,get SvelteElement(){return SvelteElement},add_attribute:add_attribute,add_classes:add_classes,add_flush_callback:add_flush_callback,add_location:add_location,add_render_callback:add_render_callback,add_resize_listener:add_resize_listener,add_transform:add_transform,afterUpdate:afterUpdate,append:append,append_dev:append_dev,assign:assign,attr:attr,attr_dev:attr_dev,beforeUpdate:beforeUpdate,bind:bind,binding_callbacks:binding_callbacks,blank_object:blank_object,bubble:bubble,check_outros:check_outros,children:children,claim_component:claim_component,claim_element:claim_element,claim_space:claim_space,claim_text:claim_text,clear_loops:clear_loops,component_subscribe:component_subscribe,createEventDispatcher:createEventDispatcher,create_animation:create_animation,create_bidirectional_transition:create_bidirectional_transition,create_component:create_component,create_in_transition:create_in_transition,create_out_transition:create_out_transition,create_slot:create_slot,create_ssr_component:create_ssr_component,get current_component(){return current_component},custom_event:custom_event,dataset_dev:dataset_dev,debug:debug,destroy_block:destroy_block,destroy_component:destroy_component,destroy_each:destroy_each,detach:detach,detach_after_dev:detach_after_dev,detach_before_dev:detach_before_dev,detach_between_dev:detach_between_dev,detach_dev:detach_dev,dirty_components:dirty_components,dispatch_dev:dispatch_dev,each:each,element:element,element_is:element_is,empty:empty,escape:escape,escaped:escaped,exclude_internal_props:exclude_internal_props,fix_and_destroy_block:fix_and_destroy_block,fix_and_outro_and_destroy_block:fix_and_outro_and_destroy_block,fix_position:fix_position,flush:flush,getContext:getContext,get_binding_group_value:get_binding_group_value,get_current_component:get_current_component,get_slot_changes:get_slot_changes,get_slot_context:get_slot_context,get_spread_object:get_spread_object,get_spread_update:get_spread_update,get_store_value:get_store_value,globals:globals,group_outros:group_outros,handle_promise:handle_promise,has_prop:has_prop,identity:identity,init:init,insert:insert,insert_dev:insert_dev,intros:intros,invalid_attribute_name_character:invalid_attribute_name_character,is_client:is_client,is_function:is_function,is_promise:is_promise,listen:listen,listen_dev:listen_dev,loop:loop,loop_guard:loop_guard,measure:measure,missing_component:missing_component,mount_component:mount_component,noop:noop,not_equal:not_equal,get now(){return now},null_to_empty:null_to_empty,object_without_properties:object_without_properties,onDestroy:onDestroy,onMount:onMount,once:once,outro_and_destroy_block:outro_and_destroy_block,prevent_default:prevent_default,prop_dev:prop_dev,get raf(){return raf},run:run,run_all:run_all,safe_not_equal:safe_not_equal,schedule_update:schedule_update,select_multiple_value:select_multiple_value,select_option:select_option,select_options:select_options,select_value:select_value,self:self,setContext:setContext,set_attributes:set_attributes,set_current_component:set_current_component,set_custom_element_data:set_custom_element_data,set_data:set_data,set_data_dev:set_data_dev,set_input_type:set_input_type,set_input_value:set_input_value,set_now:set_now,set_raf:set_raf,set_store_value:set_store_value,set_style:set_style,set_svg_attributes:set_svg_attributes,space:space,spread:spread,stop_propagation:stop_propagation,subscribe:subscribe,svg_element:svg_element,text:text,tick:tick,time_ranges_to_array:time_ranges_to_array,to_number:to_number,toggle_class:toggle_class,transition_in:transition_in,transition_out:transition_out,update_keyed_each:update_keyed_each,validate_component:validate_component,validate_store:validate_store,xlink_attr:xlink_attr}),internal$1=getCjsExportFromNamespace(internal),store=createCommonjsModule((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});const n=[];function o(t,e){return{subscribe:r(t,e).subscribe}}function r(t,e=internal$1.noop){let o;const r=[];function s(e){if(internal$1.safe_not_equal(t,e)&&(t=e,o)){const e=!n.length;for(let e=0;e<r.length;e+=1){const o=r[e];o[1](),n.push(o,t)}if(e){for(let t=0;t<n.length;t+=2)n[t][0](n[t+1]);n.length=0}}}return{set:s,update:function(e){s(e(t))},subscribe:function(n,a=internal$1.noop){const c=[n,a];return r.push(c),1===r.length&&(o=e(s)||internal$1.noop),n(t),()=>{const t=r.indexOf(c);-1!==t&&r.splice(t,1),0===r.length&&(o(),o=null)}}}}Object.defineProperty(e,"get",{enumerable:!0,get:function(){return internal$1.get_store_value}}),e.derived=function(t,e,n){const r=!Array.isArray(t),s=r?[t]:t,a=e.length<2;return o(n,t=>{let n=!1;const o=[];let c=0,i=internal$1.noop;const l=()=>{if(c)return;i();const n=e(r?o[0]:o,t);a?t(n):i=internal$1.is_function(n)?n:internal$1.noop},u=s.map((t,e)=>t.subscribe(t=>{o[e]=t,c&=~(1<<e),n&&l()},()=>{c|=1<<e}));return n=!0,l(),function(){internal$1.run_all(u),i()}})},e.readable=o,e.writable=r}));unwrapExports(store);var store_1=store.derived,store_2=store.readable,store_3=store.writable;const capital=t=>t.replace(/(^|\s)\S/,t=>t.toUpperCase()),title=t=>t.replace(/(^|\s)\S/g,t=>t.toUpperCase()),upper=t=>t.toLocaleUpperCase(),lower=t=>t.toLocaleLowerCase(),getClientLocale=({navigator:t,hash:e,search:n,fallback:o}={})=>{let r;const s=(t,e)=>{const n=t.substr(1).split("&").find(t=>0===t.indexOf(e));if(n)return n.split("=").pop()};return"undefined"!=typeof window&&(t&&(r=window.navigator.language||window.navigator.languages[0]),n&&(r=s(window.location.search,n)),e&&(r=s(window.location.hash,e))),r||o};let currentLocale,currentDictionary;const customFormats={number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}}};function addCustomFormats(t){"number"in t&&Object.assign(customFormats.number,t.number),"date"in t&&Object.assign(customFormats.date,t.date),"time"in t&&Object.assign(customFormats.time,t.time)}function getAvailableLocale(t){if(currentDictionary[t])return t;if("string"==typeof t){const e=t.split("-").shift();if(currentDictionary[e])return e}return null}const getMessageFormatter=memoize((t,e)=>new IntlMessageFormat(t,e,customFormats)),lookupMessage=memoize((t,e)=>currentDictionary[e][t]||resolvePath(currentDictionary[e],t));function formatString(t,{values:e,locale:n=currentLocale}={}){return getMessageFormatter(t,n).format(e)}function formatMessage(t,{values:e,locale:n=currentLocale}={}){const o=lookupMessage(t,n);return o?e?getMessageFormatter(o,n).format(e):o:(console.warn(`[svelte-i18n] The message "${t}" was not found in the locale "${n}".`),t)}formatMessage.time=(t,{format:e="short"}={})=>formatString(`{t,time,${e}}`,{values:{t:t}}),formatMessage.date=(t,{format:e="short"}={})=>formatString(`{d,date,${e}}`,{values:{d:t}}),formatMessage.number=(t,{format:e}={})=>formatString(`{n,number,${e}}`,{values:{n:t}}),formatMessage.capital=(t,e)=>capital(formatMessage(t,e)),formatMessage.title=(t,e)=>title(formatMessage(t,e)),formatMessage.upper=(t,e)=>upper(formatMessage(t,e)),formatMessage.lower=(t,e)=>lower(formatMessage(t,e));const dictionary=store_3({});dictionary.subscribe(t=>{currentDictionary=t});const locale=store_3({}),localeSet=locale.set;locale.set=t=>{const e=getAvailableLocale(t);if(e)return localeSet(e);throw Error(`[svelte-i18n] Locale "${t}" not found.`)},locale.update=t=>localeSet(t(currentLocale)),locale.subscribe(t=>{currentLocale=t});const format=store_1([locale,dictionary],()=>formatMessage);exports._=format,exports.addCustomFormats=addCustomFormats,exports.customFormats=customFormats,exports.dictionary=dictionary,exports.format=format,exports.formatString=formatString,exports.getClientLocale=getClientLocale,exports.locale=locale; |
{ | ||
"name": "svelte-i18n", | ||
"version": "1.1.2-beta", | ||
"main": "dist/i18n.cjs.js", | ||
"module": "src/index.js", | ||
"version": "1.1.2", | ||
"main": "dist/i18n.js", | ||
"module": "dist/i18n.mjs", | ||
"license": "MIT", | ||
@@ -53,34 +53,28 @@ "description": "Internationalization library for Svelte", | ||
}, | ||
"collectCoverage": true | ||
"collectCoverage": false | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/core": "^7.7.2", | ||
"@babel/preset-env": "^7.7.1", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^24.8.0", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.3.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.17.3", | ||
"eslint-plugin-node": "^9.1.0", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"eslint-plugin-promise": "^4.1.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.18.2", | ||
"rollup": "^1.15.1", | ||
"babel-jest": "^24.9.0", | ||
"eslint": "^6.6.0", | ||
"eslint-config-kaisermann": "0.0.3", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1", | ||
"rollup": "^1.26.5", | ||
"rollup-plugin-auto-external": "^2.0.0", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-terser": "^5.0.0", | ||
"svelte": "^3.5.1" | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"svelte": "^3.14.0" | ||
}, | ||
"peerDependencies": { | ||
"svelte": "^3.5.1" | ||
"svelte": "^3.14.0" | ||
}, | ||
"dependencies": { | ||
"intl-messageformat": "^4.0.1", | ||
"micro-memoize": "^4.0.7", | ||
"intl-messageformat": "^7.5.2", | ||
"micro-memoize": "^4.0.8", | ||
"object-resolve-path": "^1.1.1" | ||
} | ||
} |
@@ -1,5 +0,6 @@ | ||
import { writable, derived } from 'svelte/store' | ||
import { writable, derived } from 'svelte/store/index.js' | ||
import resolvePath from 'object-resolve-path' | ||
import IntlMessageFormat from 'intl-messageformat' | ||
import memoize from 'micro-memoize' | ||
import { capital, title, upper, lower, getClientLocale } from './utils.js' | ||
@@ -10,3 +11,18 @@ | ||
const getAvailableLocale = newLocale => { | ||
const customFormats = { | ||
number: { | ||
scientific: { notation: 'scientific' }, | ||
engineering: { notation: 'engineering' }, | ||
compactLong: { notation: 'compact', compactDisplay: 'long' }, | ||
compactShort: { notation: 'compact', compactDisplay: 'short' }, | ||
}, | ||
} | ||
function addCustomFormats(formats) { | ||
if ('number' in formats) Object.assign(customFormats.number, formats.number) | ||
if ('date' in formats) Object.assign(customFormats.date, formats.date) | ||
if ('time' in formats) Object.assign(customFormats.time, formats.time) | ||
} | ||
function getAvailableLocale(newLocale) { | ||
if (currentDictionary[newLocale]) return newLocale | ||
@@ -27,3 +43,3 @@ | ||
const getMessageFormatter = memoize( | ||
(message, locale, formats) => new IntlMessageFormat(message, locale, formats), | ||
(message, locale) => new IntlMessageFormat(message, locale, customFormats), | ||
) | ||
@@ -38,34 +54,38 @@ | ||
const formatMessage = (message, interpolations, locale = currentLocale) => { | ||
return getMessageFormatter(message, locale).format(interpolations) | ||
function formatString(string, { values, locale = currentLocale } = {}) { | ||
return getMessageFormatter(string, locale).format(values) | ||
} | ||
const getLocalizedMessage = (path, interpolations, locale = currentLocale) => { | ||
if (typeof interpolations === 'string') { | ||
locale = interpolations | ||
interpolations = undefined | ||
} | ||
function formatMessage(path, { values, locale = currentLocale } = {}) { | ||
const message = lookupMessage(path, locale) | ||
if (!message) return path | ||
if (!interpolations) return message | ||
if (!message) { | ||
console.warn( | ||
`[svelte-i18n] The message "${path}" was not found in the locale "${locale}".`, | ||
) | ||
return path | ||
} | ||
return getMessageFormatter(message, locale).format(interpolations) | ||
if (!values) return message | ||
return getMessageFormatter(message, locale).format(values) | ||
} | ||
getLocalizedMessage.time = (t, format = 'short', locale) => | ||
formatMessage(`{t,time,${format}}`, { t }, locale) | ||
getLocalizedMessage.date = (d, format = 'short', locale) => | ||
formatMessage(`{d,date,${format}}`, { d }, locale) | ||
getLocalizedMessage.number = (n, locale) => | ||
formatMessage('{n,number}', { n }, locale) | ||
getLocalizedMessage.capital = (path, interpolations, locale) => | ||
capital(getLocalizedMessage(path, interpolations, locale)) | ||
getLocalizedMessage.title = (path, interpolations, locale) => | ||
title(getLocalizedMessage(path, interpolations, locale)) | ||
getLocalizedMessage.upper = (path, interpolations, locale) => | ||
upper(getLocalizedMessage(path, interpolations, locale)) | ||
getLocalizedMessage.lower = (path, interpolations, locale) => | ||
lower(getLocalizedMessage(path, interpolations, locale)) | ||
formatMessage.time = (t, { format = 'short' } = {}) => | ||
formatString(`{t,time,${format}}`, { values: { t } }) | ||
formatMessage.date = (d, { format = 'short' } = {}) => | ||
formatString(`{d,date,${format}}`, { values: { d } }) | ||
formatMessage.number = (n, { format } = {}) => | ||
formatString(`{n,number,${format}}`, { values: { n } }) | ||
formatMessage.capital = (path, options) => capital(formatMessage(path, options)) | ||
formatMessage.title = (path, options) => title(formatMessage(path, options)) | ||
formatMessage.upper = (path, options) => upper(formatMessage(path, options)) | ||
formatMessage.lower = (path, options) => lower(formatMessage(path, options)) | ||
const dictionary = writable({}) | ||
@@ -84,4 +104,3 @@ dictionary.subscribe(newDictionary => { | ||
console.warn(`[svelte-i18n] Locale "${newLocale}" not found.`) | ||
return localeSet(newLocale) | ||
throw Error(`[svelte-i18n] Locale "${newLocale}" not found.`) | ||
} | ||
@@ -93,4 +112,13 @@ locale.update = fn => localeSet(fn(currentLocale)) | ||
const format = derived([locale, dictionary], () => getLocalizedMessage) | ||
const format = derived([locale, dictionary], () => formatMessage) | ||
export { locale, format as _, format, dictionary, getClientLocale } | ||
export { | ||
locale, | ||
format as _, | ||
format, | ||
formatString, | ||
dictionary, | ||
getClientLocale, | ||
customFormats, | ||
addCustomFormats, | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
70040
14
8
343
3
3
1
+ Added@formatjs/intl-unified-numberformat@3.3.7(transitive)
+ Added@formatjs/intl-utils@2.3.0(transitive)
+ Addedintl-format-cache@4.3.1(transitive)
+ Addedintl-messageformat@7.8.4(transitive)
+ Addedintl-messageformat-parser@3.6.4(transitive)
- Removedintl-messageformat@4.4.0(transitive)
- Removedintl-messageformat-parser@1.8.1(transitive)
Updatedintl-messageformat@^7.5.2
Updatedmicro-memoize@^4.0.8