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

Commit

Permalink
fix: tsc bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
irfan-maulana-tkp committed Dec 30, 2019
1 parent 127385f commit 06bac7c
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.DS_Store
node_modules
/dist
/dist-lib
/lib-out/*.js
/lib-out/*.ts

# local env files
.env.local
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ script:
- yarn build:demo
# only for test the build process
- yarn build:lib:tsc
- yarn check:size
# temporary hide
# - yarn test
# after_script:
Expand Down
39 changes: 39 additions & 0 deletions check-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require('fs');
const path = require('path');
const gzipSize = require('gzip-size');
const bytes = require('bytes');
const chalk = require('chalk');

const SKIP_FILES = ['.gitkeep']

function readDirs(dirname, onDir, onError) {
fs.readdir(dirname, function (err, filenames) {
if (err) {
onError(err);
return;
}

filenames
.filter(filename => !SKIP_FILES.includes(filename))
.map(function (filename) {
const isDir = fs.statSync(dirname + '/' + filename).isDirectory();
if (isDir) {
readDirs(dirname + '/' + filename, onDir, onError)
} else {
onDir(dirname + '/' + filename, filename);
}
});
});
}

setTimeout(() => {
readDirs(path.resolve('./lib-out/'), async (filepath, filename) => {
try {
console.log(chalk.greenBright(`> ${filename}: ${bytes(gzipSize.fileSync(filepath))}`));
} catch (err) {
console.error(err)
}
}, (err) => {
console.error(err)
})
}, 1000);
Empty file added lib-out/.gitkeep
Empty file.
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"name": "vue-currency-filter",
"description": "🍒 Lightweight vue currency filter based on accounting.js",
"version": "4.0.2",
"version": "4.0.3",
"license": "MIT",
"private": false,
"scripts": {
"dev": "vue-cli-service serve",
"serve": "vue-cli-service serve",
"prepare": "yarn build:lib:tsc",
"build:demo": "vue-cli-service build",
"build:lib": "vue-cli-service build --dest dist-lib --target lib --name VueCurrencyFilter ./src/lib/VueCurrencyFilter.ts",
"build:lib:tsc": "tsc ./src/lib/VueCurrencyFilter.ts",
"build:lib": "vue-cli-service build --dest lib-out --target lib --name VueCurrencyFilter ./src/lib/VueCurrencyFilter.ts",
"build:lib:tsc": "tsc ./src/lib/VueCurrencyFilter.ts -m CommonJS --outDir ./lib-out",
"check:size": "node ./check-size.js",
"lint": "vue-cli-service lint --fix"
},
"author": "Irfan Maulana (https://github.com/mazipan/)",
"homepage": "https://mazipan.github.io/vue-currency-filter/",
"main": "dist-lib/VueCurrencyFilter.common.js",
"module": "dist-lib/VueCurrencyFilter.common.js",
"unpkg": "dist-lib/VueCurrencyFilter.umd.min.js",
"jsdelivr": "dist-lib/VueCurrencyFilter.umd.min.js",
"main": "lib-out/VueCurrencyFilter.js",
"module": "lib-out/VueCurrencyFilter.js",
"unpkg": "lib-out/VueCurrencyFilter.js",
"jsdelivr": "lib-out/VueCurrencyFilter.js",
"typings": "types/index.d.ts",
"files": [
"dist-lib",
"lib-out",
"nuxt",
"types"
],
Expand All @@ -40,7 +42,9 @@
"peerDependencies": {
"vue": "2.6.11"
},
"dependencies": {},
"dependencies": {
"chalk": "^3.0.0"
},
"devDependencies": {
"@types/node": "12.12.22",
"@typescript-eslint/eslint-plugin": "2.13.0",
Expand All @@ -56,19 +60,21 @@
"@vue/eslint-config-typescript": "5.0.1",
"babel-eslint": "10.0.3",
"bulma-dracula": "1.0.3",
"bytes": "^3.1.0",
"core-js": "3.6.1",
"eslint": "6.8.0",
"eslint-plugin-import": "2.19.1",
"eslint-plugin-node": "11.0.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"eslint-plugin-vue": "6.1.0",
"gzip-size": "^5.1.1",
"node-sass": "4.13.0",
"prismjs": "1.17.1",
"register-service-worker": "1.6.2",
"sass-loader": "8.0.0",
"typescript": "3.7.4",
"tsc": "latest",
"typescript": "3.7.4",
"vue-class-component": "7.1.0",
"vue-google-adsense": "1.8.0",
"vue-prism-component": "1.1.1",
Expand Down
12 changes: 6 additions & 6 deletions src/lib/VueCurrencyFilter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toFixed, formatMoney } from './accounting'
import utils from './utils'
import { __isNull, __defaults } from './utils';

const VueCurrencyFilter = {
install (Vue, options) {
Expand All @@ -13,8 +13,8 @@ const VueCurrencyFilter = {
symbolSpacing: true
}

if (utils.__isNull(options)) options = {}
const globalConfigs = utils.__defaults(options, defaultConfig)
if (__isNull(options)) options = {}
const globalConfigs = __defaults(options, defaultConfig)
let { name, ...configs } = globalConfigs

const filterCurrency = function (value,
Expand All @@ -24,7 +24,7 @@ const VueCurrencyFilter = {
_fractionSeparator,
_symbolPosition,
_symbolSpacing) {
let runtimeConfig = utils.__defaults({
let runtimeConfig = __defaults({
symbol: _symbol,
thousandsSeparator: _thousandsSeparator,
fractionCount: _fractionCount,
Expand All @@ -34,7 +34,7 @@ const VueCurrencyFilter = {
}, configs)

if (typeof _symbol === 'object') {
runtimeConfig = utils.__defaults(_symbol, configs)
runtimeConfig = __defaults(_symbol, configs)
}

let result = 0.0
Expand Down Expand Up @@ -80,7 +80,7 @@ const VueCurrencyFilter = {
Vue.filter(name, filterCurrency)
Vue.prototype.$CurrencyFilter = {
setConfig: (options) => {
configs = utils.__defaults(options, defaultConfig)
configs = __defaults(options, defaultConfig)
},
getConfig: () => {
return configs
Expand Down
34 changes: 13 additions & 21 deletions src/lib/accounting.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import utils from './utils'
import { __isString, __isArray, __map, __defaults, __isObject } from './utils';

const lib = {
settings: {
Expand Down Expand Up @@ -43,7 +43,7 @@ export function checkCurrencyFormat (format) {
if (typeof format === 'function') format = format()

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

export const unformat = function (value, decimal?) {
// Recursively unformat arrays:
if (utils.__isArray(value)) {
return utils.__map(value, function (val) {
if (__isArray(value)) {
return __map(value, function (val) {
return unformat(val, decimal)
})
}
Expand Down Expand Up @@ -127,8 +127,8 @@ export const formatNumber = function (
decimal
) {
// Resursively format arrays:
if (utils.__isArray(number)) {
return utils.__map(number, function (val) {
if (__isArray(number)) {
return __map(number, function (val) {
return formatNumber(val, precision, thousand, decimal)
})
}
Expand All @@ -137,8 +137,8 @@ export const formatNumber = function (
number = unformat(number)

// Build options object from second param (if object) or all params, extending defaults:
var opts = utils.__defaults(
utils.__isObject(precision)
var opts = __defaults(
__isObject(precision)
? precision
: {
precision: precision,
Expand Down Expand Up @@ -185,8 +185,8 @@ export const formatMoney = function (
format
) {
// Resursively format arrays:
if (utils.__isArray(number)) {
return utils.__map(number, function (val) {
if (__isArray(number)) {
return __map(number, function (val) {
return formatMoney(val, symbol, precision, thousand, decimal, format)
})
}
Expand All @@ -195,8 +195,8 @@ export const formatMoney = function (
number = unformat(number)

// Build options object from second param (if object) or all params, extending defaults:
var opts = utils.__defaults(
utils.__isObject(symbol)
var opts = __defaults(
__isObject(symbol)
? symbol
: {
symbol: symbol,
Expand Down Expand Up @@ -226,11 +226,3 @@ export const formatMoney = function (
)
)
}

export default {
...lib,
unformat,
toFixed,
formatNumber,
formatMoney
}
79 changes: 41 additions & 38 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,48 @@ const nativeMap = Array.prototype.map
const nativeIsArray = Array.isArray
const toString = Object.prototype.toString

export default {
__isNull (obj: any): boolean {
return typeof obj === 'undefined' || obj === null
},
__isString (obj: any): boolean {
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr))
},
__isArray (obj: any): boolean {
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]'
},
__isObject (obj: any): boolean {
return obj && toString.call(obj) === '[object Object]'
},
__defaults (object, defs) {
var key
object = object || {}
defs = defs || {}
// Iterate over object non-prototype properties:
for (key in defs) {
// eslint-disable-next-line no-prototype-builtins
if (defs.hasOwnProperty(key)) {
// Replace values with defaults only if undefined (allow empty/zero values):
if (object[key] == null) object[key] = defs[key]
}
}
return object
},
__map (obj, iterator, context?) {
if (!obj) return []
// Use native .map method if it exists:
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context)
export function __isNull(obj: any): boolean {
return typeof obj === 'undefined' || obj === null
};

export function __isString(obj: any): boolean {
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr))
};

export function __isArray(obj: any): boolean {
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]'
};

export function __isObject(obj: any): boolean {
return obj && toString.call(obj) === '[object Object]'
};

const results = []
let i = 0
let j = 0
// Fallback for native .map:
for (i = 0, j = obj.length; i < j; i++) {
results[i] = iterator.call(context, obj[i], i, obj)
export function __defaults(object, defs) {
var key
object = object || {}
defs = defs || {}
// Iterate over object non-prototype properties:
for (key in defs) {
// eslint-disable-next-line no-prototype-builtins
if (defs.hasOwnProperty(key)) {
// Replace values with defaults only if undefined (allow empty/zero values):
if (object[key] == null) object[key] = defs[key]
}
return results
}
return object
};

export function __map(obj, iterator, context?) {
if (!obj) return []
// Use native .map method if it exists:
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context)

const results = []
let i = 0
let j = 0
// Fallback for native .map:
for (i = 0, j = obj.length; i < j; i++) {
results[i] = iterator.call(context, obj[i], i, obj)
}
return results
}
Loading

0 comments on commit 06bac7c

Please sign in to comment.