GithubHelp home page GithubHelp logo

creativeacer / spnamevalidator Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 1.0 745 KB

Tool to validate strings for use in SharePoint code

Home Page: https://www.npmjs.com/package/@creativeacer/spnamevalidator

License: MIT License

TypeScript 56.00% HTML 18.27% CSS 11.01% JavaScript 14.72%
sharepoint sharepoint-online sharepoint-2013 sharepoint-2016 validation custom-validation microsoft default-characters custom-character input-validation

spnamevalidator's Introduction

SPNameValidator CodeFactor npm version

This validator will help you validate names for SharePoint 2013/2016 or SharePoint Online.
The validation can be used for library/list names, file names and Site-Subsite names.

The purpose of this library is to check field inputs by users.
For example if a form is used to create a new list / listItem / ... this code will check if the input is valid for the selected sharepoint version.

DEFAULT - The validator uses the characters and words defined by microsoft as being illegal for both File - Folder - Library - List - Site
Donate

CUSTOM - Next to those you also have the option to set custom characters and words.

BOTH - You also have the option to validate the input on both custom and default characters and words.

I will refer to DEFAULT - CUSTOM - BOTH in the instructions

Donations

If you would like to donate anything, you can always use the following link. Much appreciated! ;)

Donate

Installation

    npm i @creativeacer/spnamevalidator

Usage

include the libary
TS

    import SPNameValidator, { Platform, ValidationType } from '@creativeacer/spnamevalidator/SPNameValidator';

JS

    var SPNameValidator = require('@creativeacer/spnamevalidator/SPNameValidator').default;
    var Platform = require('@creativeacer/spnamevalidator/SPNameValidator').Platform;
    var ValidationType = require('@creativeacer/spnamevalidator/SPNameValidator').ValidationType;

Standard SharePoint illegal char and word list

choose your SharePoint version

    let spNameValidator = new SPNameValidator(Platform["SharePoint 2013 - 2016"]);
    or
    let spNameValidator = new SPNameValidator(Platform["SharePoint Online"]);

Using checkName function!

DEFAULT - perform a check on a name / entry

    this.spNameValidator.checkName(string, ValidationType["File - Folder"]);
    or
    this.spNameValidator.checkName(string, ValidationType["ListName"]);
    or
    this.spNameValidator.checkName(string, ValidationType["Site"]);

This check will use the Default microsoft characters and words When the string is valid true will be returned.

Custom illegal char and word list

If you would like to use a custom character or wordset you can do this by setting the desired illegal characters or words:

    let customSPNameValidator = new SPNameValidator(Platform["SharePoint 2013 - 2016"]);
    or
    let customSPNameValidator = new SPNameValidator(Platform["SharePoint Online"]);

    // Set the characters and words
    this.customSPNameValidator.setIllegalCharset(['a', '#', '7']);
    this.customSPNameValidator.setIllegalWordset(['One', 'Work', 'Just']);

Characters are Case sensitive!
during validation: w !== W
words will be transformerd to uppercase
during validation: Word === WORD

Using checkCustomValue function!

CUSTOM without the default microsoft defined char and words

    this.spNameValidator.checkCustomValue(string, ValidationType["File - Folder"]);
    or
    this.spNameValidator.checkCustomValue(string, ValidationType["ListName"]);
    or
    this.spNameValidator.checkCustomValue(string, ValidationType["Site"]);

BOTH or with the default microsoft defined char and words - add true as third parameter

    this.spNameValidator.checkCustomValue(string, ValidationType["File - Folder"], true);
    or
    this.spNameValidator.checkCustomValue(string, ValidationType["ListName"], true);
    or
    this.spNameValidator.checkCustomValue(string, ValidationType["Site"], true);

When the string is valid true will be returned.

Example test for Runkit

    var SPNameValidator = require('@creativeacer/spnamevalidator/SPNameValidator').default;
    var Platform = require('@creativeacer/spnamevalidator/SPNameValidator').Platform;
    var ValidationType = require('@creativeacer/spnamevalidator/SPNameValidator').ValidationType;

    var validator = new SPNameValidator(Platform['SharePoint 2013 - 2016']);
    // should return false
    var result = validator.checkName('_test', ValidationType['File - Folder']);
    console.log('_test ' + result);
    // should return true
    var result = validator.checkName('test', ValidationType['File - Folder']);
    console.log('test ' + result);

Happy coding!

spnamevalidator's People

Contributors

creativeacer avatar dependabot[bot] avatar vansyork avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

vansyork

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.