@protoqol/directus-extension-formatted-numbers 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +55 -0
  2. package/dist/index.js +1 -0
  3. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Directus Extension: Formatted Numbers
2
+
3
+ A custom display extension for Directus that provides highly readable, localised, and abbreviated number formatting.
4
+ Perfect for dashboards and tables where space is limited or where accurate numbers are not a must.
5
+
6
+ ## Features
7
+
8
+ - **Smart Abbreviations**: Automatically scales large numbers using standard signifiers (k, M, B, T, P, E, Z, Y).
9
+ - **Localisation Support**: Correctly formats abbreviations based on the selected language (e.g., `Mrd.` for German
10
+ Billions, `億` for Japanese). Configure via the "Localisation" field option.
11
+ - **Full Value Tooltip**: Hover over any abbreviated number to see the exact, unformatted value in a tooltip.
12
+ - **Customisable Appearance**: Add custom prefixes (like currency symbols) and suffixes.
13
+
14
+ ## Configuration Options
15
+
16
+ When configuring a field to use the "Formatted numbers" display, you can customise the following options:
17
+
18
+ - **Decimals**: Set the maximum number of decimal places to display (default: 2). This controls how accurate the
19
+ displayed number is.
20
+ - **Localisation**: Choose the formatting rules for a specific language. Supported languages:
21
+ - English (en)
22
+ - French (fr)
23
+ - German (de)
24
+ - Spanish (es)
25
+ - Japanese (ja)
26
+ - Chinese (zh)
27
+ - **Prefix**: Add text or symbols before the number (e.g., `$`, `€`).
28
+ - **Suffix**: Add text or symbols after the number (e.g., ` units`, ` EUR`).
29
+
30
+ ## Examples
31
+
32
+ | Raw Value | Config | Output |
33
+ |:----------------------|:------------------|:------------|
34
+ | `1,234,567` | `en`, 2 decimals | `1.23M` |
35
+ | `123,456,789,000` | `de`, 1 decimal | `123,5Mrd.` |
36
+ | `5,000` | `en`, prefix: `$` | `$5K` |
37
+ | `100,000,000,000,000` | `en` | `100T` |
38
+
39
+ ## Supported Scales
40
+
41
+ The extension supports values from thousands up to septillions. Do you require more? Open an issue and we'll add
42
+ it!
43
+
44
+ - **K**: Kilo (10³)
45
+ - **M**: Mega (10⁶)
46
+ - **B / G**: Giga / Billion (10⁹)
47
+ - **T**: Tera / Trillion (10¹²)
48
+ - **P**: Peta / Quadrillion (10¹⁵)
49
+ - **E**: Exa (10¹⁸)
50
+ - **Z**: Zetta (10²¹)
51
+ - **Y**: Yotta (10²⁴)
52
+
53
+ ---
54
+
55
+ Developed by [Protoqol](https://protoqol.nl/).
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{defineDisplay as e}from"@directus/extensions-sdk";import{defineComponent as i,createElementBlock as r,openBlock as t,toDisplayString as s}from"vue";var n=i({props:{value:{type:Number,default:null},rounding:{type:Number,default:2},lang:{type:String,default:"en"},prefix:{type:String,default:""},suffix:{type:String,default:""}},computed:{formattedValue(){if(null===this.value||void 0===this.value)return"–";let e="";const i=Math.abs(this.value),r=this.value<0?"-":"";let t={en:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"T"},{threshold:1e9,signifier:"B"},{threshold:1e6,signifier:"M"},{threshold:1e3,signifier:"K"}],fr:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"Bn"},{threshold:1e9,signifier:"Md"},{threshold:1e6,signifier:"M"},{threshold:1e3,signifier:"k"}],de:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"Bio."},{threshold:1e9,signifier:"Mrd."},{threshold:1e6,signifier:"Mio."},{threshold:1e3,signifier:"Tsd."}],es:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"B"},{threshold:1e9,signifier:"mil M"},{threshold:1e6,signifier:"M"},{threshold:1e3,signifier:"mil"}],ja:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"兆"},{threshold:1e8,signifier:"億"},{threshold:1e4,signifier:"万"}],zh:[{threshold:1e24,signifier:"Y"},{threshold:1e21,signifier:"Z"},{threshold:1e18,signifier:"E"},{threshold:1e15,signifier:"P"},{threshold:1e12,signifier:"万亿"},{threshold:1e8,signifier:"亿"},{threshold:1e4,signifier:"万"}]}[this.lang].find(e=>i>=e.threshold);if(t){let s=i/t.threshold,n="";if(n=s.toFixed(this.rounding).replace(/\.?0+$/,""),n.length>5)for(let e=this.rounding-1;e>=0&&(n=s.toFixed(e).replace(/\.?0+$/,""),!(n.length<=5));e--);e=r+n+t.signifier}else e=new Intl.NumberFormat(void 0,{minimumFractionDigits:0,maximumFractionDigits:this.rounding}).format(this.value);return`${this.prefix||""}${e}${this.suffix||""}`},fullValue(){return null===this.value||void 0===this.value?"":(new Intl.NumberFormat).format(this.value)}}});const h=["title"];var l=e({id:"protoqol-formatted-numbers",name:"Formatted numbers",icon:"forward_media",description:"Format numbers in a (localised) readable way.",component:((e,i)=>{const r=e.__vccOpts||e;for(const[e,t]of i)r[e]=t;return r})(n,[["render",function(e,i,n,l,o,d){return t(),r("div",{title:e.fullValue},s(e.formattedValue),9,h)}]]),options:[{field:"rounding",name:"Decimals",type:"integer",meta:{width:"half",interface:"input",options:{placeholder:"2",min:0}}},{field:"lang",name:"Localisation",type:"string",meta:{width:"half",interface:"select-dropdown",options:{choices:[{text:"English",value:"en"},{text:"French",value:"fr"},{text:"German",value:"de"},{text:"Spanish",value:"es"},{text:"Japanese",value:"ja"},{text:"Chinese",value:"zh"}]}},schema:{default_value:"en"}},{field:"prefix",name:"Prefix",type:"string",meta:{width:"half",interface:"input",options:{placeholder:"€"}}},{field:"suffix",name:"Suffix",type:"string",meta:{width:"half",interface:"input",options:{placeholder:"EUR"}}}],types:["integer","bigInteger"]});export{l as default};
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name" : "@protoqol/directus-extension-formatted-numbers",
3
+ "license" : "MIT",
4
+ "description" : "Directus extension: Format numbers in a easily readable way. With localisation available!",
5
+ "icon" : "forward_media",
6
+ "version" : "1.0.0",
7
+ "keywords" : [
8
+ "directus",
9
+ "directus-extension",
10
+ "directus-extension-display"
11
+ ],
12
+ "type" : "module",
13
+ "files" : [
14
+ "dist"
15
+ ],
16
+ "directus:extension": {
17
+ "type" : "display",
18
+ "path" : "dist/index.js",
19
+ "source": "src/index.ts",
20
+ "host" : "^10.10.0"
21
+ },
22
+ "scripts" : {
23
+ "build" : "directus-extension build",
24
+ "dev" : "directus-extension build -w --no-minify",
25
+ "link" : "directus-extension link",
26
+ "validate": "directus-extension validate"
27
+ },
28
+ "devDependencies" : {
29
+ "@directus/extensions-sdk": "17.0.5",
30
+ "typescript" : "^5.9.3",
31
+ "vue" : "^3.5.27"
32
+ }
33
+ }