Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit 06bac7c

Browse files
fix: tsc bundle
1 parent 127385f commit 06bac7c

File tree

9 files changed

+139
-94
lines changed

9 files changed

+139
-94
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.DS_Store
22
node_modules
33
/dist
4-
/dist-lib
4+
/lib-out/*.js
5+
/lib-out/*.ts
56

67
# local env files
78
.env.local

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ script:
1414
- yarn build:demo
1515
# only for test the build process
1616
- yarn build:lib:tsc
17+
- yarn check:size
1718
# temporary hide
1819
# - yarn test
1920
# after_script:

check-size.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const gzipSize = require('gzip-size');
4+
const bytes = require('bytes');
5+
const chalk = require('chalk');
6+
7+
const SKIP_FILES = ['.gitkeep']
8+
9+
function readDirs(dirname, onDir, onError) {
10+
fs.readdir(dirname, function (err, filenames) {
11+
if (err) {
12+
onError(err);
13+
return;
14+
}
15+
16+
filenames
17+
.filter(filename => !SKIP_FILES.includes(filename))
18+
.map(function (filename) {
19+
const isDir = fs.statSync(dirname + '/' + filename).isDirectory();
20+
if (isDir) {
21+
readDirs(dirname + '/' + filename, onDir, onError)
22+
} else {
23+
onDir(dirname + '/' + filename, filename);
24+
}
25+
});
26+
});
27+
}
28+
29+
setTimeout(() => {
30+
readDirs(path.resolve('./lib-out/'), async (filepath, filename) => {
31+
try {
32+
console.log(chalk.greenBright(`> ${filename}: ${bytes(gzipSize.fileSync(filepath))}`));
33+
} catch (err) {
34+
console.error(err)
35+
}
36+
}, (err) => {
37+
console.error(err)
38+
})
39+
}, 1000);

lib-out/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
{
22
"name": "vue-currency-filter",
33
"description": "🍒 Lightweight vue currency filter based on accounting.js",
4-
"version": "4.0.2",
4+
"version": "4.0.3",
55
"license": "MIT",
66
"private": false,
77
"scripts": {
88
"dev": "vue-cli-service serve",
99
"serve": "vue-cli-service serve",
10+
"prepare": "yarn build:lib:tsc",
1011
"build:demo": "vue-cli-service build",
11-
"build:lib": "vue-cli-service build --dest dist-lib --target lib --name VueCurrencyFilter ./src/lib/VueCurrencyFilter.ts",
12-
"build:lib:tsc": "tsc ./src/lib/VueCurrencyFilter.ts",
12+
"build:lib": "vue-cli-service build --dest lib-out --target lib --name VueCurrencyFilter ./src/lib/VueCurrencyFilter.ts",
13+
"build:lib:tsc": "tsc ./src/lib/VueCurrencyFilter.ts -m CommonJS --outDir ./lib-out",
14+
"check:size": "node ./check-size.js",
1315
"lint": "vue-cli-service lint --fix"
1416
},
1517
"author": "Irfan Maulana (https://github.com/mazipan/)",
1618
"homepage": "https://mazipan.github.io/vue-currency-filter/",
17-
"main": "dist-lib/VueCurrencyFilter.common.js",
18-
"module": "dist-lib/VueCurrencyFilter.common.js",
19-
"unpkg": "dist-lib/VueCurrencyFilter.umd.min.js",
20-
"jsdelivr": "dist-lib/VueCurrencyFilter.umd.min.js",
19+
"main": "lib-out/VueCurrencyFilter.js",
20+
"module": "lib-out/VueCurrencyFilter.js",
21+
"unpkg": "lib-out/VueCurrencyFilter.js",
22+
"jsdelivr": "lib-out/VueCurrencyFilter.js",
2123
"typings": "types/index.d.ts",
2224
"files": [
23-
"dist-lib",
25+
"lib-out",
2426
"nuxt",
2527
"types"
2628
],
@@ -40,7 +42,9 @@
4042
"peerDependencies": {
4143
"vue": "2.6.11"
4244
},
43-
"dependencies": {},
45+
"dependencies": {
46+
"chalk": "^3.0.0"
47+
},
4448
"devDependencies": {
4549
"@types/node": "12.12.22",
4650
"@typescript-eslint/eslint-plugin": "2.13.0",
@@ -56,19 +60,21 @@
5660
"@vue/eslint-config-typescript": "5.0.1",
5761
"babel-eslint": "10.0.3",
5862
"bulma-dracula": "1.0.3",
63+
"bytes": "^3.1.0",
5964
"core-js": "3.6.1",
6065
"eslint": "6.8.0",
6166
"eslint-plugin-import": "2.19.1",
6267
"eslint-plugin-node": "11.0.0",
6368
"eslint-plugin-promise": "4.2.1",
6469
"eslint-plugin-standard": "4.0.1",
6570
"eslint-plugin-vue": "6.1.0",
71+
"gzip-size": "^5.1.1",
6672
"node-sass": "4.13.0",
6773
"prismjs": "1.17.1",
6874
"register-service-worker": "1.6.2",
6975
"sass-loader": "8.0.0",
70-
"typescript": "3.7.4",
7176
"tsc": "latest",
77+
"typescript": "3.7.4",
7278
"vue-class-component": "7.1.0",
7379
"vue-google-adsense": "1.8.0",
7480
"vue-prism-component": "1.1.1",

src/lib/VueCurrencyFilter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { toFixed, formatMoney } from './accounting'
2-
import utils from './utils'
2+
import { __isNull, __defaults } from './utils';
33

44
const VueCurrencyFilter = {
55
install (Vue, options) {
@@ -13,8 +13,8 @@ const VueCurrencyFilter = {
1313
symbolSpacing: true
1414
}
1515

16-
if (utils.__isNull(options)) options = {}
17-
const globalConfigs = utils.__defaults(options, defaultConfig)
16+
if (__isNull(options)) options = {}
17+
const globalConfigs = __defaults(options, defaultConfig)
1818
let { name, ...configs } = globalConfigs
1919

2020
const filterCurrency = function (value,
@@ -24,7 +24,7 @@ const VueCurrencyFilter = {
2424
_fractionSeparator,
2525
_symbolPosition,
2626
_symbolSpacing) {
27-
let runtimeConfig = utils.__defaults({
27+
let runtimeConfig = __defaults({
2828
symbol: _symbol,
2929
thousandsSeparator: _thousandsSeparator,
3030
fractionCount: _fractionCount,
@@ -34,7 +34,7 @@ const VueCurrencyFilter = {
3434
}, configs)
3535

3636
if (typeof _symbol === 'object') {
37-
runtimeConfig = utils.__defaults(_symbol, configs)
37+
runtimeConfig = __defaults(_symbol, configs)
3838
}
3939

4040
let result = 0.0
@@ -80,7 +80,7 @@ const VueCurrencyFilter = {
8080
Vue.filter(name, filterCurrency)
8181
Vue.prototype.$CurrencyFilter = {
8282
setConfig: (options) => {
83-
configs = utils.__defaults(options, defaultConfig)
83+
configs = __defaults(options, defaultConfig)
8484
},
8585
getConfig: () => {
8686
return configs

src/lib/accounting.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utils from './utils'
1+
import { __isString, __isArray, __map, __defaults, __isObject } from './utils';
22

33
const lib = {
44
settings: {
@@ -43,7 +43,7 @@ export function checkCurrencyFormat (format) {
4343
if (typeof format === 'function') format = format()
4444

4545
// Format can be a string, in which case `value` ("%v") must be present:
46-
if (utils.__isString(format) && format.match('%v')) {
46+
if (__isString(format) && format.match('%v')) {
4747
// Create and return positive, negative and zero formats:
4848
return {
4949
pos: format,
@@ -54,7 +54,7 @@ export function checkCurrencyFormat (format) {
5454
// If no format, or object is missing valid positive value, use defaults:
5555
} else if (!format || !format.pos || !format.pos.match('%v')) {
5656
// If defaults is a string, casts it to an object for faster checking next time:
57-
return !utils.__isString(defaults)
57+
return !__isString(defaults)
5858
? defaults
5959
// @ts-ignore
6060
: (lib.settings.currency.format = {
@@ -69,8 +69,8 @@ export function checkCurrencyFormat (format) {
6969

7070
export const unformat = function (value, decimal?) {
7171
// Recursively unformat arrays:
72-
if (utils.__isArray(value)) {
73-
return utils.__map(value, function (val) {
72+
if (__isArray(value)) {
73+
return __map(value, function (val) {
7474
return unformat(val, decimal)
7575
})
7676
}
@@ -127,8 +127,8 @@ export const formatNumber = function (
127127
decimal
128128
) {
129129
// Resursively format arrays:
130-
if (utils.__isArray(number)) {
131-
return utils.__map(number, function (val) {
130+
if (__isArray(number)) {
131+
return __map(number, function (val) {
132132
return formatNumber(val, precision, thousand, decimal)
133133
})
134134
}
@@ -137,8 +137,8 @@ export const formatNumber = function (
137137
number = unformat(number)
138138

139139
// Build options object from second param (if object) or all params, extending defaults:
140-
var opts = utils.__defaults(
141-
utils.__isObject(precision)
140+
var opts = __defaults(
141+
__isObject(precision)
142142
? precision
143143
: {
144144
precision: precision,
@@ -185,8 +185,8 @@ export const formatMoney = function (
185185
format
186186
) {
187187
// Resursively format arrays:
188-
if (utils.__isArray(number)) {
189-
return utils.__map(number, function (val) {
188+
if (__isArray(number)) {
189+
return __map(number, function (val) {
190190
return formatMoney(val, symbol, precision, thousand, decimal, format)
191191
})
192192
}
@@ -195,8 +195,8 @@ export const formatMoney = function (
195195
number = unformat(number)
196196

197197
// Build options object from second param (if object) or all params, extending defaults:
198-
var opts = utils.__defaults(
199-
utils.__isObject(symbol)
198+
var opts = __defaults(
199+
__isObject(symbol)
200200
? symbol
201201
: {
202202
symbol: symbol,
@@ -226,11 +226,3 @@ export const formatMoney = function (
226226
)
227227
)
228228
}
229-
230-
export default {
231-
...lib,
232-
unformat,
233-
toFixed,
234-
formatNumber,
235-
formatMoney
236-
}

src/lib/utils.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,48 @@ const nativeMap = Array.prototype.map
22
const nativeIsArray = Array.isArray
33
const toString = Object.prototype.toString
44

5-
export default {
6-
__isNull (obj: any): boolean {
7-
return typeof obj === 'undefined' || obj === null
8-
},
9-
__isString (obj: any): boolean {
10-
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr))
11-
},
12-
__isArray (obj: any): boolean {
13-
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]'
14-
},
15-
__isObject (obj: any): boolean {
16-
return obj && toString.call(obj) === '[object Object]'
17-
},
18-
__defaults (object, defs) {
19-
var key
20-
object = object || {}
21-
defs = defs || {}
22-
// Iterate over object non-prototype properties:
23-
for (key in defs) {
24-
// eslint-disable-next-line no-prototype-builtins
25-
if (defs.hasOwnProperty(key)) {
26-
// Replace values with defaults only if undefined (allow empty/zero values):
27-
if (object[key] == null) object[key] = defs[key]
28-
}
29-
}
30-
return object
31-
},
32-
__map (obj, iterator, context?) {
33-
if (!obj) return []
34-
// Use native .map method if it exists:
35-
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context)
5+
export function __isNull(obj: any): boolean {
6+
return typeof obj === 'undefined' || obj === null
7+
};
8+
9+
export function __isString(obj: any): boolean {
10+
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr))
11+
};
12+
13+
export function __isArray(obj: any): boolean {
14+
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]'
15+
};
16+
17+
export function __isObject(obj: any): boolean {
18+
return obj && toString.call(obj) === '[object Object]'
19+
};
3620

37-
const results = []
38-
let i = 0
39-
let j = 0
40-
// Fallback for native .map:
41-
for (i = 0, j = obj.length; i < j; i++) {
42-
results[i] = iterator.call(context, obj[i], i, obj)
21+
export function __defaults(object, defs) {
22+
var key
23+
object = object || {}
24+
defs = defs || {}
25+
// Iterate over object non-prototype properties:
26+
for (key in defs) {
27+
// eslint-disable-next-line no-prototype-builtins
28+
if (defs.hasOwnProperty(key)) {
29+
// Replace values with defaults only if undefined (allow empty/zero values):
30+
if (object[key] == null) object[key] = defs[key]
4331
}
44-
return results
4532
}
33+
return object
34+
};
35+
36+
export function __map(obj, iterator, context?) {
37+
if (!obj) return []
38+
// Use native .map method if it exists:
39+
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context)
40+
41+
const results = []
42+
let i = 0
43+
let j = 0
44+
// Fallback for native .map:
45+
for (i = 0, j = obj.length; i < j; i++) {
46+
results[i] = iterator.call(context, obj[i], i, obj)
47+
}
48+
return results
4649
}

0 commit comments

Comments
 (0)