1.0.4 • Published 6 years ago

awesome-matrix v1.0.4

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

awesome-matrix

This is a simple two-dimensional matrix library written by TypeScript that receives input options from the user.

  • This is written in TypeScript
  • Provides basically five patterns.

Installation

npm install awesome-matrix

Usage

import { IMatrixStrategy, RightUpwardRightTriangle, SquareMatrix } from 'awesome-matrix'

export class RightUpwardRightTriangle implements IMatrixStrategy {
    public twoDimensionArrayLogic(degree: number, stringShape: string): string[][] {
        const twoDimensionArray: string[][] = []
        // ...
        return twoDimensionArray
    }
}

const rightUp = new RightUpwardRightTriangle()
rightUp.twoDimensionArrayLogic(5, '@') // => twoDimensionArrayLogic(degree, shapeCharacter)

const matrix = new SquareMatrix('&', new RightUpwardRightTriangle()) // => SquareMatrix(shapeCharacter, pattern)
matrix.executePattern(7) // => executePattern(degree)
  • provided API
export { LeftDownwardRightTriangle } from 'awesome-matrix'
export { LeftUpwardRightTriangle } from 'awesome-matrix'
export { PyramidTriangle } from 'awesome-matrix'
export { RightDownwardRightTriangle } from 'awesome-matrix'
export { RightUpwardRightTriangle } from 'awesome-matrix'
export { SquareMatrix, IMatrixStrategy } from 'awesome-matrix'

Examples

import { IMatrixStrategy, SquareMatrix, LeftUpwardRightTriangle, PyramidTriangle } from 'awesome-matrix'

// get print shape '&' and pattern LeftUpward-RightTriangle
const leftUpward = new SquareMatrix('&', new LeftUpwardRightTriangle())
leftUpward.executePattern(7) // => degree : 7

// get print shape 'K' and pattern Pyramid
const pyramid = new SquareMatrix('K', new PyramidTriangle())
pyramid.executePattern(3) // => degree: 3

CLI

  • help
$ matrix -h
  • Usage
Usage: matrix [Option]
Option :
    -h : Display this help message
    -p=pattern : pattern is one of (pyramid | leftUpward | rightUpward | leftDownward | rightDownward)
    -s=character : Users can choose the shape character (defaultValue -s=\*)
    -d=degree : Users can set the order of array (defaultValue -d=5)

$ matrix -d=degree (default option : pattern and shapeCharacter)
$ matrix -p=patterns -s=shapeCharacter -d=degree
  • Example
$ matrix

/* default matrix
      @
     @@@
    @@@@@
*/
$ matrix -p=leftUpward -s=# -d=6

/* conditional matrix
    #
    ##
    ###
    ####
    #####
    ######
*/
$ matrix -p=rightDownward -s=D

/* partial conditional matrix (degree is default(5))
    DDDDD
     DDDD
      DDD
       DD
        D
*/
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago