typescript(option): chore: fixed build process
Signed-off-by: prescientmoon <git@moonythm.dev>
This commit is contained in:
parent
906096a5cb
commit
6f93885507
|
@ -3,8 +3,8 @@
|
|||
"version": "0.0.0-development",
|
||||
"description": "Typescript version of fsharps Option module",
|
||||
"main": "dist/bundle.cjs.js",
|
||||
"module": "dist/bundle.esm.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"module": "dist/index.esm.js",
|
||||
"typings": "dist/index.esm.d.ts",
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "rollup -c rollup.config.ts"
|
||||
|
@ -24,15 +24,15 @@
|
|||
],
|
||||
"sideEffects": false,
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^11.0.0",
|
||||
"@rollup/plugin-node-resolve": "^6.0.0",
|
||||
"@types/node": "^12.12.21",
|
||||
"@wessberg/rollup-plugin-ts": "^1.1.83",
|
||||
"rimraf": "^3.0.0",
|
||||
"rollup": "^1.27.13",
|
||||
"rollup-plugin-commonjs": "^10.1.0",
|
||||
"rollup-plugin-dts": "^1.1.13",
|
||||
"rollup-plugin-terser": "^5.1.3",
|
||||
"rollup-plugin-typescript2": "^0.25.3",
|
||||
"semantic-release": "^15.13.31",
|
||||
"typescript": "^3.7.3"
|
||||
"semantic-release": "^15.14.0",
|
||||
"typescript": "^3.7.4"
|
||||
},
|
||||
"author": "Matei Adriel",
|
||||
"license": "SEE LICENSE IN LICENSE"
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,6 @@
|
|||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import nodeResolve from '@rollup/plugin-node-resolve'
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import typescript from 'rollup-plugin-typescript2'
|
||||
import { terser } from 'rollup-plugin-terser'
|
||||
import { resolve } from 'path'
|
||||
import ts from '@wessberg/rollup-plugin-ts'
|
||||
|
||||
const outputDirectory = resolve(__dirname, 'dist')
|
||||
const inputFile = resolve(__dirname, 'src/index.ts')
|
||||
|
@ -19,36 +16,36 @@ export default [
|
|||
external,
|
||||
output: [
|
||||
{
|
||||
file: `${outputDirectory}/bundle.cjs.js`,
|
||||
file: `${outputDirectory}/index.cjs.js`,
|
||||
format: 'cjs',
|
||||
sourcemap: true
|
||||
},
|
||||
{
|
||||
file: `${outputDirectory}/bundle.esm.js`,
|
||||
format: 'esm',
|
||||
sourcemap: true
|
||||
},
|
||||
{
|
||||
file: `${outputDirectory}/bundle.amd.js`,
|
||||
file: `${outputDirectory}/index.amd.js`,
|
||||
sourcemap: true,
|
||||
format: 'amd',
|
||||
name: 'Option'
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
nodeResolve({
|
||||
extensions: ['.ts']
|
||||
}),
|
||||
commonjs(),
|
||||
typescript({
|
||||
tsconfig: resolve(__dirname, 'tsconfig.json')
|
||||
}),
|
||||
!dev && terser()
|
||||
]
|
||||
plugins: [ts(), !dev && terser()]
|
||||
},
|
||||
{
|
||||
input: inputFile,
|
||||
output: [{ file: `${outputDirectory}/index.d.ts`, format: 'es' }],
|
||||
plugins: [dts()]
|
||||
external,
|
||||
output: [
|
||||
{
|
||||
file: `${outputDirectory}/index.esm.js`,
|
||||
format: 'esm',
|
||||
sourcemap: true
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
ts({
|
||||
tsconfig: {
|
||||
declaration: true
|
||||
}
|
||||
}),
|
||||
!dev && terser()
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -10,18 +10,16 @@ import {
|
|||
import { identity } from './internalHelperts'
|
||||
import { none, some } from './internals'
|
||||
|
||||
export const isSome = <T>(option: Option<T>): option is Some<T> =>
|
||||
option.type === some
|
||||
export const isNothing = <T>(option: Option<T>): option is None =>
|
||||
option.type === none
|
||||
export const isSome = <T>(option: Option<T>) => option._type === some
|
||||
export const isNothing = <T>(option: Option<T>) => option._type === none
|
||||
|
||||
const match = <T, U>(
|
||||
caseSome: Mapper<T, U>,
|
||||
_default: U,
|
||||
option: Option<T>
|
||||
) => {
|
||||
if (isSome(option)) {
|
||||
return caseSome(option.value as T)
|
||||
if (option._type === some) {
|
||||
return caseSome(option.value)
|
||||
}
|
||||
|
||||
return _default
|
||||
|
@ -72,7 +70,7 @@ export const forall = <T>(predicate: Predicate<T>, option: Option<T>) => {
|
|||
}
|
||||
|
||||
export const get = <T>(option: Option<T>): T => {
|
||||
if (isSome(option)) {
|
||||
if (option._type === some) {
|
||||
return option.value
|
||||
}
|
||||
|
||||
|
@ -80,7 +78,7 @@ export const get = <T>(option: Option<T>): T => {
|
|||
}
|
||||
|
||||
export const iter = <T>(mapper: Mapper<T, void>, option: Option<T>) => {
|
||||
if (isSome(option)) {
|
||||
if (option._type === some) {
|
||||
mapper(option.value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export const some = Symbol('some')
|
||||
export const none = Symbol('none')
|
||||
export const some = 'some'
|
||||
export const none = 'none'
|
||||
|
||||
export type NominalTyped<T, U> = {
|
||||
type: T
|
||||
_type: T
|
||||
value: U
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
import { NominalTyped, none, some } from './internals'
|
||||
|
||||
export type None = NominalTyped<typeof none, null>
|
||||
export type Some<T> = NominalTyped<typeof some, T>
|
||||
export type None = NominalTyped<'none', null>
|
||||
export type Some<T> = NominalTyped<'some', T>
|
||||
|
||||
export type Option<T> = Some<T> | None
|
||||
|
||||
export const None: Option<any> = {
|
||||
type: none,
|
||||
_type: 'none',
|
||||
value: null
|
||||
}
|
||||
|
||||
export const Some = <T>(value: T): Option<T> => ({
|
||||
type: some,
|
||||
_type: 'some',
|
||||
value
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue