1.1.5 • Published 2 years ago

momentum-constructor-common v1.1.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

momentum-constructor-common

momentum-constructor-common is a tool to offer common modules for momentum-constructor-packages.

Install

npm i momentum-constructor-common

Usage

You can go to ./test to check the detail usage.

mfs

mfs is a file system mode in momentum-constructor-common.

import { mfs } from 'momentum-constructor-common';

or

const { mfs } = require('momentum-constructor-common');

path

Get the full path of where you installed momentum-abstract.

arguments

nametypedescription
momentumTypeMomentumAbstractTypeThe data type

return

typedescription
stringthe folder path

usage

  • read momentum-abstract/color path
const pathString = mfs.path(MomentumAbstractType.color);
  • read momentum-abstract/icon path
const pathString = mfs.path(MomentumAbstractType.icon);

list

Get a file name list from momentum-abstract.

arguments

nametypedescription
momentumTypeMomentumAbstractTypeThe data type
filterIFileFilterblacklist and whitelist

return

typedescription
string[]file name list

usage

  • read momentum-abstract/color list
const files = mfs.list(MomentumAbstractType.color);
  • read momentum-abstract/color list with filter
let files = mfs.list(MomentumAbstractType.color, {
    whitelist: [/.json$/i]
});

read

Get a list of files from momentum-abstract.

arguments

nametypedescription
momentumTypeMomentumAbstractTypeThe data type
filterIFileFilterblacklist and whitelist

return

typedescription
Record<string, IFile>Hash Object for files

usage

  • read momentum-abstract/color json files
let files = mfs.read(MomentumAbstractType.color);

mcommon

mcommon is a common mode in momentum-constructor-common.

import { mcommon } from 'momentum-constructor-common';

or

const { mcommon } = require('momentum-constructor-common');

getRegFromNames

Create a regular expression using an array of filenames.

arguments

nametypedescription
fileNameListstring[]The list of file name

return

typedescription
RegExpRegExp for filter

getRegFromNamesSafe

getRegFromNamesSafe has the same arguments and return with getRegFromNames. RegExp has a max-length limitation, we do some check in this function.

mconvert

mconvert offers the feature to convert momentum files'name and content.

import { mconvert } from 'momentum-constructor-common';

or

const { mconvert } = require('momentum-constructor-common');

renameFile

rename all the files

arguments

nametypedescription
mometnumFilesRecord<string, IFile>the file from mfs.read
replacementIReplacementItemreplacement

return

typedescription
Record<string, IFile>RegExp for filter

renameToken

rename the token in the content

arguments

nametypedescription
mometnumFilesRecord<string, IFile>the file from mfs.read
replacementIReplacementItemreplacement
momentumTypeMomentumAbstractTypeThe data type

return

typedescription
Record<string, IFile>RegExp for filter

flat

flat the content

arguments

nametypedescription
mometnumFilesRecord<string, IFile>the file from mfs.read
momentumTypeMomentumAbstractTypeThe data type

return

typedescription
Record<string, IFile>RegExp for filter

Types

import { MomentumAbstractType } from 'momentum-constructor-common';

or

const { MomentumAbstractType } = require('momentum-constructor-common');

Enum

MomentumAbstractType ( * for reserved name, not use)

namedescription
colorcolor tokens
fontfont tokens
illustrationillustration icons
iconnormal icons
icon-coloredcolored icons
icon-brandbrand icons
sonicsound effect

Interface & Type

IFile

proptypedescription
pathstringthe full file path
contentanyfile content
contentCode?stringcode type
namestringfile name without extension
fullNamestringfile name with extension
extensionNamestringextension such as '.svg'
  • rule for reading content
file typecontent type
.svgstring
.jsonjson ojbect
defaultbuffer[]

IFileFilter

proptypedescription
whitelistRegExp[]only return files whose filename matches the condition
blacklistRegExp[]only return files whose filename does not match the condition

IReplacementItem

proptypedescription
patternstringRegExpwhich part you want to replace
wordsstringanythe new wording
1.1.5

2 years ago

1.1.4

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago