Skip to content

typescript-package/affix

Repository files navigation

typescript-package/affix

npm version GitHub issues GitHub license

version: v4.0.0

A lightweight TypeScript library for different kind of affixes.


Table of contents

Installation

1. Install peer dependencies

npm install @typedly/affix --save-peer

2. Install the package

npm install @typescript-package/affix --save-peer

Api

import {
  // Abstract.
  AffixCore,
  // Class.
  Affix,
  Circumfix,
  Infix,
  Prefix,
  Suffix,
} from '@typescript-package/affix';

AffixCore

A core abstract class to manage affixes with the value and kind that can be applied to strings.

import { AffixCore } from '@typescript-package/affix';

class Prefix extends AffixCore<string, 'prefix'> {
  constructor(value: string) {
    super(value, 'prefix');
  }
}

Affix

A concrete class to manage affixes that can be applied to strings with additional sanitization.

import { Affix } from '@typescript-package/affix';

export const prefix = new Affix("testAffixValue",  {
  kind: 'prefix' as BasicAffixKind,
  pattern: /[^a-zA-Z0-9$_]/g,
});

Circumfix

A class to manage circumfixes that can be applied to strings.

import { Circumfix } from '@typescript-package/affix';

const circumfix = new Circumfix(
  'pre', // Start
  'post', // End
  /[^a-zA-Z0-9$_]/g // Pattern
);

circumfix.insertTo(
  'light' // Stem
); // 'prelightpost'

Infix

A class to manage infixes that can be applied to strings.

import { Infix } from '@typescript-package/affix';

const infix = new Infix('en');

infix.insertTo(
  'light', // stem
  5 // position
); // 'lighten'
infix.insertTo(
  'light', // stem
  0 // position
); // 'enlight'
infix.insertTo(
  'light', // stem
  1, // position
  '-' // delimiter
); // 'l-en-ight'

Prefix

A class to manage prefixes that can be applied to strings.

import { Prefix } from '@typescript-package/affix';

const prefix = new Prefix(
  'pre', // Value
  /[^a-zA-Z0-9$_]/g // Pattern
);

prefix.prependTo(
  'stem', // stem
  '-' // delimiter
); // 'pre-stem'

console.debug(`default => `, Prefix.default); // ''
console.debug(`pattern => `, Prefix.pattern); // RegExp /[^a-zA-Z0-9$_]/g
console.debug(`tagName => `, Prefix.tagName); // 'Prefix'

console.debug(`kind => `, prefix.kind); // 'prefix'
console.debug(`pattern => `, prefix.pattern); // RegExp /[^a-zA-Z0-9$_]/g
console.debug(`prefix => `, prefix.prefix); // 'pre'
console.debug(`toStringTag => `, prefix[Symbol.toStringTag]); // 'Prefix'
console.debug(`value => `, prefix.value); // 'pre'

console.debug(`prefix.get()`, prefix.get()); // 'pre'
console.debug(`prefix.set({value: 'newPrefix'}) => `, prefix.set({value: 'newPrefix' as any}).value); // 'newPrefix'

console.debug(`prefix.setKind('newKind') => `, prefix.setKind('newKind' as any).kind); // 'newKind'
console.debug(`prefix.setPattern(/newPattern/g) => `, prefix.setPattern(/newPattern/g).pattern); // /newPattern/g
console.debug(`prefix.setValue('newValue') => `, prefix.setValue('newValue' as any).value); // 'newValue'

Suffix

A class to manage suffixes that can be applied to strings.

import { Suffix } from '@typescript-package/affix';

export const suffix = new Suffix(
  'post', // Value
  /[^a-zA-Z0-9$_]/g // Pattern
);

Suffix.append(
  'stem',
  'post',
  '-'
); // 

Contributing

Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.

Support

If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.

Support via:

or via Trust Wallet

Thanks for your support!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Versioning

Semantic Versioning 2.0.0

Given a version number MAJOR.MINOR.PATCH, increment the:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards-compatible manner, and
  • PATCH version when you make backwards-compatible bug fixes.

Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

FAQ How should I deal with revisions in the 0.y.z initial development phase?

The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.

How do I know when to release 1.0.0?

If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.

License

MIT © angular-package (license)

About

A lightweight TypeScript library for different kind of affixes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •