How to use the pluralize.isSingular function in pluralize

To help you get started, we’ve selected a few pluralize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Riim / Maraquia / src / BaseModel.ts View on Github external
if (fieldSchema.type) {
					let fieldType = fieldSchema.type();

					if (fieldType.$schema.collectionName) {
						if (value !== null) {
							let isArray = Array.isArray(value);

							if (!isArray || value.length) {
								if ((isArray ? value[0] : value) instanceof ObjectId) {
									this[KEY_VALUES].set(name, isArray ? value.slice() : value);
								} else {
									if (
										isArray &&
										value.length == 1 &&
										!(value[0] instanceof BaseModel) &&
										isSingular(name)
									) {
										value = value[0];
										isArray = false;
									}

									if (!((isArray ? value[0] : value) instanceof BaseModel)) {
										value = isArray
											? value.map(
													(itemData: Object) =>
														new fieldType(itemData, db)
											  )
											: new fieldType(value, db);
										data[name] = value;
									}

									this._validateFieldValue(name, fieldSchema, value);
github infinitered / gluegun / src / toolbox / string-tools.ts View on Github external
pluralize.isSingular = (word: string) => require('pluralize').isSingular(word)
github Riim / Maraquia / dist / BaseModel.js View on Github external
}
                let value = value_ === undefined ? null : value_;
                if (fieldSchema.type) {
                    let fieldType = fieldSchema.type();
                    if (fieldType.$schema.collectionName) {
                        if (value !== null) {
                            let isArray = Array.isArray(value);
                            if (!isArray || value.length) {
                                if ((isArray ? value[0] : value) instanceof mongodb_1.ObjectId) {
                                    this[exports.KEY_VALUES].set(name, isArray ? value.slice() : value);
                                }
                                else {
                                    if (isArray &&
                                        value.length == 1 &&
                                        !(value[0] instanceof BaseModel) &&
                                        pluralize_1.isSingular(name)) {
                                        value = value[0];
                                        isArray = false;
                                    }
                                    if (!((isArray ? value[0] : value) instanceof BaseModel)) {
                                        value = isArray
                                            ? value.map((itemData) => new fieldType(itemData, db))
                                            : new fieldType(value, db);
                                        data[name] = value;
                                    }
                                    this._validateFieldValue(name, fieldSchema, value);
                                    let valuePromise = Promise.resolve(value);
                                    valuePromise[exports.KEY_VALUE] = isArray ? value.slice() : value;
                                    this[exports.KEY_VALUES].set(name, valuePromise);
                                }
                                continue;
                            }