1.1.2 • Published 2 years ago

momentum-constructor-name v1.1.2

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

momentum-constructor-name

momentum-constructor-name is a tool to format momentum-abstract's token name or file name.

Release Nots

Install

npm i momentum-constructor-name

Usage

import

    const { Convertor } = require('momentum-constructor-name');

or

    import { Convertor } from 'momentum-constructor-name';

Convertors

You can use Convertor to create the instance to start work.

  • usage
const { Convertor } = require('momentum-constructor-name');
const path = require('path');
myConvertor = new Convertor({
    type: 'color',
    output: path.resolve(__dirname,'./output/color'),
    flat: true, // default false
    replacement: {
        token: {
            pattern: /\-/g,
            words: '@'
        },
        fileName: {
            pattern: /c/g,
            words: 'a'
        }
    }
});

Options

  • IOption
proptypedescription
typeMomentumAbstractTypeCheck in momentum-constructor-common
outputstringthe output directory
flatbooleanif remove extra layer in json
replacementojbectthe rules of replacement
  • replacement
proptypedescription
tokenIReplacementrule for token
fileNameIReplacementrule for file name
  • IReplacementItem
proptypedescription
patternstringRegExpDefine what is replaced
wordsstringfunctionDefine new words

method

convert

This method will return a json object. The key of return object is file path while the value is file content. And this method will update the property 'files' of the instance.

  • usage
myConvertor.convert();
Object.values(myConvertor.files).forEach((file)=>{
    /*
        your code
        file.content
        file.path
    */
});

rename

Rename all the files and save them into output directory. This method will not change the token name.

  • usage
myConvertor.rename();

save

Rename all the files and save them into output directory. This method will change the token name.

  • usage
myConvertor.save();

clean

Clear the output directory. If the directory does not exist, create one.

  • usage
myConvertor.clean();
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago